37

I tried changing the addTypeName: false in the Apollo client in GraphQL

apollo.create({
  link: httpLinkWithErrorHandling,
  cache: new InMemoryCache({ addTypename: false }),
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'network-only',
      errorPolicy: 'all'
    }
  }

But it works and it throws the following messages in the console

fragmentMatcher.js:26 You're using fragments in your queries, but either don't have the addTypename:true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename.Please turn on the addTypename option and include __typename when writing fragments so that Apollo Clientcan accurately match fragments.

,

Could not find __typename on Fragment  PopulatedOutageType

and

fragmentMatcher.js:28 DEPRECATION WARNING: using fragments without __typename is unsupported behavior and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.

even if i change false to true new InMemoryCache({ addTypename: true }), the mutations start failing because of the unwanted typename in the mutation

is there any way to resolve this issue

Rigin Oommen
  • 3,060
  • 2
  • 20
  • 29
  • 1
    Asked and answered here: [Apollo boost - \_\_typename in query prevent new mutation](https://stackoverflow.com/questions/52873741/apollo-boost-typename-in-query-prevent-new-mutation). If you're using a query results as initial state, you'll need to transform it first to strip out the `__typename` fields (and any other fields that may not be valid input fields). – Daniel Rearden Mar 20 '19 at 12:03

1 Answers1

15

Cleaning Unwanted Fields From GraphQL Responses

In the above thread, I have posted the answer for this problem please refer to it

Rigin Oommen
  • 3,060
  • 2
  • 20
  • 29
  • 5
    Probably worth noting that this will likely break caching unless you make adjustments. https://github.com/apollographql/apollo-client/issues/2881 – Jake Oct 04 '19 at 22:14
  • 1
    This question was more generalized but got more attention and has a more reviewed answer. https://stackoverflow.com/questions/47211778/cleaning-unwanted-fields-from-graphql-responses – Jake Oct 04 '19 at 22:26