-
Notifications
You must be signed in to change notification settings - Fork 991
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
Allow GraphQL documents to be typed with a TypedDocumentNode for fully-typed result and variables objects #9619
Conversation
@Tobbe and others: one question I had is if the generators should be updated to detect if using TS and infer types as above. If som, we can make this a separate PR enhancement to update the generators. |
@dthyresson Initial reaction, without looking at any code, is yes, we should, and yes, let’s do that in a separate PR 🙂 |
|
…od into feat/api-skip-prebuild-try-2 * 'feat/api-skip-prebuild-try-2' of github.com:dac09/redwood: chore(router): Miniscule fixes chore(router): Move useMatch to its own file (redwoodjs#9770) Allow GraphQL documents to be typed with a TypedDocumentNode for fully-typed result and variables objects (redwoodjs#9619) chore(ci): retry detectChanges on error, and await result (redwoodjs#9772)
Fixes #9232
See the above issue for key points.
TLDR;
Before this PR, it wasn't possible to infer types from the
useQuery
oruseMutation
GraphQL hooks.Also,
TypedDocumentNode
was not conveniently exported from@redwoodjs/web
(and is now).Now, you can do:
and infer types:
For context:
See https://the-guild.dev/blog/typed-document-node
TypedDocumentNode is a development tool that allows you to create fully typed DocumentNode objects. This means that by simply passing your GraphQL query, mutation, subscription, or fragment to a supporting GraphQL client library, you'll get fully-typed result and variables objects. This is made possible by TypeScript type inference.