-
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 to pass generics to DocumentNode
to allow TS type inference by GraphQL clients
#2728
Allow to pass generics to DocumentNode
to allow TS type inference by GraphQL clients
#2728
Conversation
Hi @IvanGoncharov , @leebyron how can we progress with this one? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally for adding wrapping type for DocumentNode
.
But It should be a separate type since the template argument is never used in DocumentNode
or any other node. Plus DocumentNode
can also contain SDL definitions.
So it should be separate type inherited from DocumentNode
e.g. TypedQueryDocumentNode
or something similar.
But I'm fully against changes to graphql
/execute
:
- We shouldn't provide typings for something we can't guarantee. For example, we plan to merge
@defer
that will change payload and it would be different from type generated bygraphql-codegen
. The same goes for other custom directives that change payload or custom scalars that have representation other that string. - What are production use cases for typing the result of
execute
/graphql
? Client queries are sent over the wire and we don't have type info on the server. I understand how typed queries are helpful on the client but I struggle to understand why it's needed on the server.
Summary: I understand how useful it would be to bind type info to query and share it between other tools so I'm fully for adding this type. However, I strongly disagree with reference implementation providing typings for execute
/graphql
that it can't guarantee to be in sync with what is actually returned.
Thank you @IvanGoncharov for the review! @ForbesLindesay suggested (dotansimha/graphql-typed-document-node#34) to add internal types to Regarding
@IvanGoncharov what do you think about the following: I can remove all the changes from I don't think adding a new type called |
@IvanGoncharov I updated the PR with the minimal changes possible, in order to support that. What do you think? |
Source
and DocumentNode
to allow TS type inferenceDocumentNode
to allow TS type inference by GraphQL clients
@dotansimha Thanks 👍 |
Thanks @IvanGoncharov . Are you open to keep it as part of the original |
@dotansimha Sorry missed that in you previous comment.
Here is a snippet that
|
Resolves #2727