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.

MockedProvider gives incorrect error message with undefined variables

See original GitHub issue

Intended outcome:

MockedProvider error message correctly describes GraphQL request missing a mock when no matching mock present

Actual outcome:

No more mocked responses for the query: query GetIssues($a: ID, $b: ID, $c: String!, $d: String!) {
      getIssues(a: $a, b $b, c: $c, d: $d) {
        id
        name
      }
    }
    , variables: {"a":"123","c":"456","d":"789"}

Note that the query I am sending actually has b: undefined in the variables, and that’s why the mock (which did not include b in the variables) did not match, but MockedProvider did not tell me this.

How to reproduce the issue:

Set up a mock for a query that takes an optional variable, pass undefined to it in your code, but omit it from variables in your mock. It will fail to match, but the error message will not mention it.

Versions

  System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
  Binaries:
    Node: 13.8.0 - ~/n/bin/node
    Yarn: 1.22.0 - ~/duboce-labs/pganalyze/node_modules/.bin/yarn
    npm: 6.14.4 - ~/n/bin/npm
  Browsers:
    Chrome: 84.0.4147.89
    Firefox: 78.0.2
  npmPackages:
    @apollo/client: ^3.0.2 => 3.0.2 
    apollo: ^2.23.0 => 2.23.0 
  npmGlobalPackages:
    apollo: 2.18.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
vithcommented, May 26, 2021

I don’t think #7108 fixed this.

I’ve offered a fix for the error message, and some failing tests for the mock matching behavior itself in #8285

Can we reopen?

4reactions
benjamncommented, Jul 23, 2020

To be completely honest with you, we did not get around to improving our testing/mocking utilities in AC3, but they are badly in need of an update, and this is a great example of a shortcoming in how the mocking utilities match queries/variables. Thanks for opening this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

apollo's MockedProvider doesn't warn clearly about missing ...
The idea is to give the MockedProvider a custom apollo link. By default, it uses MockLink initialized with the given mocks.
Read more >
Debugging Apollo GraphQL MockedProvider - Swarmia
When seeing this error, we know that Apollo MockProvider received query getDogParent from a component but no matching mock was found. The phrase ......
Read more >
Testing React components - Apollo GraphQL Docs
The MockedProvider component. Every test for a React component that uses Apollo Client must make Apollo Client available on React's context.
Read more >
How to fix Apollo's MockedProvider returning empty objects for ...
<MockedProvider addTypename={false} mocks={MOCKS}> ... but your response provides it, it fails silently, and you get an empty response.
Read more >
Gotchas using React Apollo MockProvider | by Tomoaki Imai
To get a more precise error message, let's add InMemoryCache as props of MockProvider. <MockedProvider mocks={mocks} addTypename cache={
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