-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
graphql.link() doesn't intercept request #342
Comments
Hi @hugotiburtino thanks for opening the issue :). I have looked at your code and I think that your implementation is right. The problem I think is how graphql requests are handled in the Lines 76 to 91 in 2478051
The operation name from parse function is null for your case because This makes me worry about another thing, in a single graphql request multiple query can be send but I think that this not handled. |
A GraphQL request must be named in order to be matched with MSW. In your example you have an untitled request. -{ _cacheKeys: {} }
+query GetCacheKeys { _cacheKeys: {} } You use the name of the query when creating a request handler: import { graphql } from 'msw'
graphql.query('GetCacheKeys', resolver) We are currently elaborating on supporting an operation-based interception (#184), so stay tuned for updates. |
@marcosvega91, I think you are right. Would you be interested in adding a new integration test to MSW to illustrate that we fail to handle a scenario when a single request contains multiple named GraphQL queries? |
Thanks, that solved my issue |
Yes I'll create a test case :) |
I have looked better to the spec and there is no official support for multi query in a single operation so I think that we are good for now 😄 |
I think there was a confusion over query name and fields. Each query has a single name, but may request multiple fields. # `GetUser` is the name
query GetUser($userId: String!) {
# `user` is a field
user: {
firstName
lastName
}
# `subscriptions` is a field
subscriptions: {
filterBy(userId: $userId) {
validUntil
}
}
} |
Yes I thought that a single fetch with multiple operations could be possibile. Do we want to add a test case with your example? |
I think there is no need. That test is going to assert that given JSON produces the respective response body. We already have such test. |
Environment
Request handlers
Actual request
Current behavior
The request by-passes the interceptor and goes to the actual server, which responds with 400 (since the feature doesn't exit yet).
Expected behavior
To get the same response that I have when I mock the GraphQL server using the rest object
To Reproduce
git clone https://github.com/hugotiburtino/api.serlo.org.git
(commit 80b09a)yarn install
yarn test __tests__/worker.ts
The text was updated successfully, but these errors were encountered: