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 ignores variables when doing matching #1412

Closed
paradite opened this Issue Dec 18, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@paradite
Copy link

paradite commented Dec 18, 2017

Intended outcome:

MockedProvider should serialise query as well as variables passed into it and mock requests accordingly.

Actual outcome:
MockedProvider only serialises query but not variables passed into it, causing any request with arbitrary variables to be matched with the mocked request with the same query.

How to reproduce the issue:

The buggy code is here:

return JSON.stringify(requestKey, Object.keys(requestKey).sort());

const requestKey = {
    variables: request.variables || {},
    query: queryString,
  };
JSON.stringify(requestKey, Object.keys(requestKey).sort());

When serialising the requestKey, variables field would get lost.

Sample code to reproduce the issue:

var requestKey = {
  query: 'something',
  variables: {
    a: 'else',
  }
}

console.log(JSON.stringify(requestKey, Object.keys(requestKey).sort()));
// {"query":"something","variables":{}}
// variables empty, because 'a' is not in the array passed to JSON.stringify as second parameter

console.log(JSON.stringify(requestKey, ['query', 'variables', 'a']));
// {"query":"something","variables":{"a":"else"}}
// variables present, because 'a' is in the array passed to JSON.stringify as second parameter

console.log(JSON.stringify(requestKey));
// {"query":"something","variables":{"a":"else"}}
// variables present, because no filtering

Version

  • apollo-client@1.9.1
  • react-apollo@1.4.14
@rosskevin

This comment has been minimized.

Copy link
Collaborator

rosskevin commented Dec 18, 2017

PR welcome!

@paradite

This comment has been minimized.

Copy link
Author

paradite commented Dec 19, 2017

Okay, will try to send a PR soon.

@excitement-engineer

This comment has been minimized.

Copy link
Collaborator

excitement-engineer commented Dec 31, 2017

I fixed it, see #1501

@paradite

This comment has been minimized.

Copy link
Author

paradite commented Jan 1, 2018

Wow, nice. Sorry I kind of forgot about it and moved on.

jbaxleyiii pushed a commit that referenced this issue Jan 4, 2018

The mocks now take into account the specific variables used. Fixes #1412
 (#1501)

* The mocks now take into account the specific variables used. Fixes #1412

* changelog

* removed unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment