apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

`MockLink` doesn't work with `@nonreactive` directive. #11781

Closed broyde closed 6 months ago

broyde commented 7 months ago

Issue Description

The same query is used for main code and mocked response in test. This works fine until we add @nonreactive directive to this query. Query example:

const query = gql`
query TestQuery {
  photos {
    id
    url @nonreactive
  }
}
`;

Warning example:

     No more mocked responses for the query: query TestQuery {
        photos {
          id
          url
          __typename
        }
      }
      Expected variables: {}

Whole test: https://github.com/broyde/apollo-mock-nonreactive/blob/main/nonreactive.test.js

It would be great to automatically remove @nonreactive from mocks passed to MockLink/MockedProvider. It should help to match actually performed query with the mocked one.

Link to Reproduction

https://github.com/broyde/apollo-mock-nonreactive

Reproduction Steps

No response

@apollo/client version

3.9.11

jerelmiller commented 7 months ago

Hey @broyde!

Thanks for bringing this to our attention! It looks like we might need to run internal document transforms on the queries passed to MockLink to ensure they match. I don't have a timeline on a fix for this, but we'll take a look when we get to it. Again, thanks for reporting it!

github-actions[bot] commented 6 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] commented 5 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.