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

Add TypedDocumentNode support #139

Merged

Conversation

ardatan
Copy link
Contributor

@ardatan ardatan commented Oct 4, 2021

Thank you for this great library!
This PR adds TypedDocumentNode support to graphql-jit. For example, generated TypedDocumentNode queries will have type safe signature with graphql-jit.
It also enables to use generics in CompiledQuery to have better type safety.
https://github.com/dotansimha/graphql-typed-document-node

package.json Show resolved Hide resolved
@ardatan
Copy link
Contributor Author

ardatan commented Oct 6, 2021

Is there anything I can do to get this merged?

@oporkka
Copy link
Member

oporkka commented Oct 7, 2021

Is there anything I can do to get this merged?

We have to get two Zalando employees to review this PR. As the reviewers might not be familiar with TypedDocumentNode, my proposal would be to extend the PR description to extend why adding support for TypedDocumentNode is needed. I see it's about type safety, but how would the experience of users of GraphQL-jit improve? Do you have any code examples? Do the current users need to change their code somehow if this gets merged and they update GraphQL-jit?

@dotansimha
Copy link

dotansimha commented Nov 1, 2021

Is there anything I can do to get this merged?

We have to get two Zalando employees to review this PR. As the reviewers might not be familiar with TypedDocumentNode, my proposal would be to extend the PR description to extend why adding support for TypedDocumentNode is needed. I see it's about type safety, but how would the experience of users of GraphQL-jit improve? Do you have any code examples? Do the current users need to change their code somehow if this gets merged and they update GraphQL-jit?

Sure.

GraphQL-Codegen generates a ready-to-use TypedDocumentNode (it's basically a DocumentNode with the response and variables types burned into the type).
When a user passes this TypedDocumentNode to GraphQL-JIT's execute function, it gets type-safety out of the box (because of TypeScript's type-inference):

const executionResult = await compiledQuery.query(root, context, variables);
// Now, executionResult is fully typed automatically, and variables is also checked. 

This way, developers don't need to specify types manually at all. TypedDocumentNode is now adopted by graphql-js, apollo-client, urql and many other popular libraries. This only modifies the types signature of graphql-jit and add support for TypedDocumentNode, without introducing any code change or a breaking change.

@ruiaraujo
Copy link
Collaborator

@ardatan please run the formatter. This PR lgtm!

@ardatan
Copy link
Contributor Author

ardatan commented Nov 1, 2021

I think it is good now! @ruiaraujo

@ruiaraujo
Copy link
Collaborator

👍

@ruiaraujo
Copy link
Collaborator

@ardatan i believe you are pushing code to the wrong branch.

@ardatan ardatan force-pushed the typed-document-node-support branch from 77d4bb3 to 937a4d9 Compare November 1, 2021 14:54
@ardatan
Copy link
Contributor Author

ardatan commented Nov 1, 2021

@ruiaraujo Yes I realized that :) I cherrypicked those commits to the other PR

@ardatan
Copy link
Contributor Author

ardatan commented Nov 1, 2021

Ok I fixed lint/format issue because of the new import.

@ruiaraujo
Copy link
Collaborator

👍

@ardatan
Copy link
Contributor Author

ardatan commented Nov 1, 2021

I think it is ready to merge right? @ruiaraujo

@ruiaraujo
Copy link
Collaborator

Once a colleague from zalando approves, it will be merged.

@ardatan
Copy link
Contributor Author

ardatan commented Nov 1, 2021

@boopathi Could you review please? :)

@addityasingh
Copy link
Contributor

👍

@addityasingh addityasingh merged commit d75988c into zalando-incubator:master Nov 1, 2021
@ardatan ardatan deleted the typed-document-node-support branch November 1, 2021 17:24
@addityasingh addityasingh mentioned this pull request Nov 1, 2021
10 tasks
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

Successfully merging this pull request may close these issues.

6 participants