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#2728dotansimha wants to merge 2 commits intographql:masterfrom dotansimha:feature/ts-document-node-generics
DocumentNode to allow TS type inference by GraphQL clients#2728Conversation
|
Hi @IvanGoncharov , @leebyron how can we progress with this one? thanks! |
There was a problem hiding this comment.
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
@deferthat 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