-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Support TypedDocumentNode in graphql contracts #773
Comments
Hey, @longility. Thanks for suggesting this. It looks like an interesting idea to explore, let's elaborate on it. I'm not familiar with So From what I can see at the moment, supporting
msw/src/handlers/GraphQLHandler.ts Line 29 in 2213b4e
msw/src/handlers/GraphQLHandler.ts Lines 98 to 106 in 2213b4e
msw/src/utils/internal/parseGraphQLRequest.ts Lines 25 to 40 in 2213b4e
// In the GraphQLHandler constructor:
const { operationName: parsedOperationName } = parseQuery(operationName)
constructor(operationType, operationName, ...rest) {
if (operationName instanceof DocumentNode) {
const { operationType: parsedOperationType } = parseQuery(operationName)
if (parsedOperationType !== operationType) {
throw new Error('Invalid DocumentNode provided: expected "${operationType}", got "${parsedOperationType}"')
}
}
}
Once we've set the handler's Please, @longility, would you be interested in leading this effort? |
Yep, I heard about @kettanaito thanks for the quick analysis and guidance. If you are okay with me taking a couple of weeks as I can't dedicate my time on this, then I'm okay leading this effort. |
For sure, there's no rush. Thank you for your help, @longility! |
Is your feature request related to a problem? Please describe.
I would like consistent usage of
TypedDocumentNode
approach for graphql operations and mocks (msw) to minimize cognitive load, coupling, and explicit types needing to be added.Describe the solution you'd like
I would like to be able to do this
instead of this
Describe alternatives you've considered
I did not consider other alternatives as it seems straightforward.
Additional context
If you haven't heard of
TypedDocumentNode
, here are some referencesQuestions
The text was updated successfully, but these errors were encountered: