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

[3.0-beta] MockedProvider: addTypename does not work with @client #6016

Closed timonkbd closed 3 years ago

timonkbd commented 4 years ago

Intended outcome:

The following query should match with the provided mock when testing a component that queries the local state using the @client directive:

query GetLocalState {
  paletteType @client
}
const mocks = [
  {
    request: { query: GetLocalStateQuery },
    result: { data: { paletteType: 'dark' } },
  },
];

const resolvers = {};

const wrapper = mount(
  <MockedProvider mocks={mocks} resolvers={resolvers} addTypename={false}>
    <ComponentWithLocalState />
  </MockedProvider>
);

Actual outcome:

I had no problems using the approach above with apollo-client@2.6.8, but after the migration to @apollo/client@3.0-beta the mock only matches the query when removing @client or adding the __typename field. So I guess it has something to do with the addTypename prop.

query GetLocalState {
  paletteType
}
query GetLocalState {
  __typename
  paletteType @client
}

How to reproduce the issue:

I think the above explanation should make the problem clear and reproducible. If I find time (and if needed), I can also try to set up a repository to reproduce the problem.

Versions

OS: macOS 10.15.3

Node: 10.16.3 npm: 6.9.0

@apollo/client: 3.0.0-beta.38 @apollo/link-error: 2.0.0-beta.3 @apollo/react-ssr: 4.0.0-beta.1 next-with-apollo: 5.0.0

hwillson commented 3 years ago

This should no longer be an issue in @apollo/client@latest - let us know otherwise, thanks!