graphql.link() doesn't intercept request
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.20.5 |
node | 12.18.3 |
OS | Ubuntu 20.04 |
Request handlers
const serloApi = graphql.link('https://api.serlo.org/graphql')
global.server.use(
serloApi.query('_cacheKeys', async(req, res, ctx) =>{
return res(
ctx.data(
await server.executeOperation({
query: worker.queryLiteral,
} as GraphQLRequest)
)
)
})
)
})
Actual request
import { GraphQLClient, gql } from 'graphql-request'
...
private query = gql`{ _cacheKeys (first: 5, after: ...
await this.grahQLClient.request(this.query).then(async (data) => console.log('data: ', data))
...
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).
Cannot query field "_cacheKeys" on type "Query".: {"response":{"errors":[{"message":"Cannot query field \"_cacheKeys\" on type \"Query\".","locations":[{"line":2,"column":7}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}}],"status":400},"request":{"query":"\n { _cacheKeys (first: 5, after: \"\") { edges { cursor node } nodes totalCount pageInfo { hasNextPage hasPreviousPage startCursor endCursor } } }\n "}}
Expected behavior
To get the same response that I have when I mock the GraphQL server using the rest object
data: {
_cacheKeys: {
edges: [ [Object], [Object], [Object], [Object], [Object] ],
nodes: [ 'key0', 'key1', 'key2', 'key3', 'key4' ],
totalCount: 25,
pageInfo: {
hasNextPage: true,
hasPreviousPage: false,
startCursor: 'a2V5MA==',
endCursor: 'a2V5NA=='
}
}
}
To Reproduce
git clone https://github.com/hugotiburtino/api.serlo.org.git
(commit 80b09a)yarn install
yarn test __tests__/worker.ts
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Advanced HTTP networking - Apollo GraphQL Docs
Take full network control with Apollo Link. The Apollo Link library gives you fine-grained control of HTTP requests that are sent by Apollo...
Read more >Cypress does not intercept GraphQL API calls - Stack Overflow
I am trying to intercept a graphql mutation to access its response. Cypress doesn't notice the request and cy.wait() times out.
Read more >Debugging uncaught requests - Recipes - Mock Service Worker
Whenever you are faced with a request that is not being intercepted, follow the suggestions on this page to debug the issue.
Read more >Using Postman Interceptor
Select the URL in the URL column to open the request as a new API request in Postman. When you select one or...
Read more >Spring for GraphQL Documentation
By default, the Boot starter does not expose a GraphQL over WebSocket ... Server transports allow intercepting requests before and after the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 😄