question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

graphql.link() doesn't intercept request

See original GitHub issue

Environment

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

  1. git clone https://github.com/hugotiburtino/api.serlo.org.git (commit 80b09a)
  2. yarn install
  3. yarn test __tests__/worker.ts

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kettanaitocommented, Aug 21, 2020

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.

1reaction
marcosvega91commented, Aug 20, 2020

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 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found