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.

Stripped @connection directive breaks MockedProvider

See original GitHub issue

Intended outcome: I have a test that uses a MockedProvider to test a given GraphQL query. This test was running smoothly with apollo@1.9.1, but broke once we migrated to 2.0.2. This is the query we are testing:

query WidgetData($id: ID!, $parameter: JSON) {
    widgetData(id: $id, parameter: $parameter) @connection(key: $id)
}

Actual outcome: We get this error: Error: Network error: No more mocked responses for the query: query WidgetData($id: ID!, $parameter: JSON) { widgetData(id: $id, parameter: $parameter) }, variables: {"id":"id1"}]

As it turns out, the problem is that the mocked response is saved under the key

'{"query":"query WidgetData($id: ID!, $parameter: JSON) {\n  widgetData(id: $id, parameter: $parameter) @connection(key: $id)\n}\n","variables":{}}'

while it is retrieved under the slightly different key:

 '{"query":"query WidgetData($id: ID!, $parameter: JSON) {\n  widgetData(id: $id, parameter: $parameter)\n}\n","variables":{}}'

So the @connection(key: $id) directive is stripped in the second line, which results in the mock data not being returned correctly.

After lots of debugging, we found the culprit to be this change, where the connect directive is deliberately stripped out: https://github.com/apollographql/apollo-client/pull/2375/files#diff-fde964badaf130f363bd0d1f7bc71b26R121

Version

  • apollo-client@2.0.2
  • react-apollo@2.0.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
lewisl9029commented, Jul 24, 2018

Unfortunately, I was able to repro this issue using apollo-client 2.3.5 and react-apollo 2.1.8. apollo-link is likely stripping the connection directive as expected, but as far as I can see, nothing in MockedLink appears to be stripping the connection directive in the user provided queries in MockedProvider’s mocks prop, so the queries won’t match exactly: https://github.com/apollographql/react-apollo/blob/master/src/test-links.ts#L40

I can open a PR to address this for the @connection directive since it’s likely just a matter of calling removeConnectionDirectiveFromDocument from apollo-utilities in addMockedResponse: https://github.com/apollographql/react-apollo/blob/master/src/test-links.ts#L46

But I’m not sure yet what it’d take to generalize this to other client side directives, or if this is even necessary for any other directive?

0reactions
htulipecommented, Mar 28, 2019

From what I can tell, it is fixed in client 2.5

Read more comments on GitHub >

github_iconTop Results From Across the Web

@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
https://raw.githubusercontent.com/apollostack/reac...
... `@connection` directives are now properly stripped from ... Bug Fixes - Make sure `MockedProvider` enables Apollo Client 2.5's local state handling, ...
Read more >
pact-broker
i am making use of pact stub server to bring up the mocked provider(https://github.com/uglyog/pact-stub-server), for this can i link the pact files that...
Read more >
react-apollo: Versions - Openbase
@connection directives are now properly stripped from MockedResponse 's, ... Make sure MockedProvider enables Apollo Client 2.5's local state handling, ...
Read more >
Fullstack Graphql Book r2 - (2020) | PDF | Information Age ... - Scribd
It can be used language and framework agnostic, and connected to any ... The MockedProvider exposes a mocked apollo client with a set...
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