Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL queries fail if the input contains any unknown fields #140

Open
toolness opened this issue Sep 13, 2018 · 3 comments
Open

GraphQL queries fail if the input contains any unknown fields #140

toolness opened this issue Sep 13, 2018 · 3 comments

Comments

@toolness
Copy link
Collaborator

While working on #139, I ran into a runtime error because I was passing a query to GraphQL that included a superset of the required input. TypeScript doesn't normally care about this, which is why it didn't complain, but the GraphQL server did care. It would be nice to solve this somehow at the type-checking level, e.g. perhaps there's an Exact<T> mapped type that makes sure that any fields not in T are never or something.

Barring that, we could add code to the queryfetcher that explicitly picks only the keys it needs from the input, but that will add code bloat and also might be non-trivial since I don't think queryfetcher actually understands anything about the structure of its inputs.

@toolness toolness added this to the Cleanup for First Milestone milestone Sep 13, 2018
@toolness
Copy link
Collaborator Author

toolness commented Sep 15, 2018

I did a bit of research on this and it looks like there's an open issue for this kind of thing in TypeScript already. There are a few suggested workarounds, I think my favorite of which is microsoft/TypeScript#12936 (comment), but after tinkering with our code a bit it looks like it would require a fair amount of refactoring to support.

Yet another solution might actually be to modify our GraphQL server to simply ignore unrecognized input fields rather than throwing; however, if it's standard behavior for a GraphQL server to error when this happens, instead of merely a Graphene-specific idiosyncrasy, I'd prefer to avoid this solution.

@toolness
Copy link
Collaborator Author

Working on #213, I added a getInitialState() in landlord-details.tsx that is almost exactly like the one in letter-request.tsx (which was added in #139). I realized, though, that there's a way we can dynamically remove any irrelevant fields in our session state that aren't in our default state in getInitialState(). (Both getInitialState()s so far work by seeing if there is session state they can use, and falling back to a hard-coded default state if not.)

@toolness
Copy link
Collaborator Author

I've mitigated this in #217 with a helper function but I'm going to leave this issue open as a low-priority one because it'd still be nice to not have to remember to use the helper.

@toolness toolness removed this from the Cleanup for First Milestone milestone Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant