-
Notifications
You must be signed in to change notification settings - Fork 2k
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 result type and variables type to be inferred from DocumentNode
/Source
using TypeScript type system
#2727
Comments
DocumentNode
using TypeScript type system? DocumentNode
/Source
using TypeScript type system
Apollo Client would gladly use this type, and we think it would be ideal for it to be provided by the same package that defines |
@dotansimha @benjamn I'm totally for adding |
@dotansimha @benjamn I went ahead and merged #2749 can you please test it using npm branch: |
@dotansimha can this be closed? Is there additional pending integration with TypedDocumentNode? |
While this was pending, most GraphQL client libraries adopted the original |
Fantastic! |
Yeah, but I think in this repo we have a similar type, that's probably unused... :X |
Hi!
We recently implemented an improved version of
DocumentNode
, calledTypedDocumentNode
, that allow type generics for result type and variables type:This improved version allows TypeScript to infer the types automatically when an object that matches the signature is used, for example:
This will allow to have the types set within the
DocumentNode
and not externally as used today, and avoid incorrect TypeScript types used.This made possible because TypeScript does type inference when possible.
The existing solution is implemented in this repo: https://github.com/dotansimha/graphql-typed-document-node and it's currently implemented by patching
graphql
library and add support to it. I think this concept could be merged into this PR, just like we allowextensions
or other to be typed with generics.Developers who chose to automate the typings creation, can use GraphQL Code Generator to generate a pre-compiled
DocumentNode<T, R>
from their operations, the output file looks like that:https://github.com/dotansimha/graphql-typed-document-node/blob/master/examples/graphql/typed-document-nodes.ts#L45
Adding this to the core implementation of
graphql
won't break anything, since it effects only TypeScript types, and the generics are mostly there today, so it's just a few non-breaking adjustments to support this.To have it fully supported across
graphql
andexecute
method, it needs to be added toSource
andDocumentNode
. I created a PR here: #2728Related:
@IvanGoncharov
The text was updated successfully, but these errors were encountered: