Skip to content
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

MockedProvider gives incorrect error message with undefined variables #6688

Open
msakrejda opened this issue Jul 23, 2020 · 5 comments
Open

Comments

@msakrejda
Copy link

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
@benjamn
Copy link
Member

benjamn commented 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!

@benjamn benjamn added this to the Post 3.0 milestone Jul 23, 2020
@tonnenpinguin
Copy link

I've been running into the same issue a lot lately.

What helped me was to monkey patch the testing.js file with the contents of this old pr: https://github.com/apollographql/react-apollo/pull/2883/files

With that you get a proper diff on what is expected vs what was actually found in your mocks

benjamn added a commit that referenced this issue Oct 1, 2020
See benjamn/wryware#21 for explanation and
motivation. Should help with #6771, #6803, #6688, #6378, and #7081, and
possibly other regressions that began in @apollo/client@3.1.0.
benjamn added a commit that referenced this issue Oct 1, 2020
See benjamn/wryware#21 for explanation and
motivation. Should help with #6771, #6803, #6688, #6378, and #7081, and
possibly other regressions that began in @apollo/client@3.1.0.
@benjamn
Copy link
Member

benjamn commented Oct 1, 2020

This behavior should be fixed/improved in @apollo/client@3.3.0-beta.9 (just published to npm), thanks to #7108. Please give it another try after updating!

@hwillson
Copy link
Member

hwillson commented May 4, 2021

It doesn't sound like there is an outstanding issue here, so closing. Thanks!

@vith
Copy link

vith commented 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?

@hwillson hwillson reopened this May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants