Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the `__typename` field from the graphql response which fails the mutations

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

like image 556
Rigin Oommen Avatar asked Mar 20 '19 11:03

Rigin Oommen


People also ask

What is __ Typename in GraphQL?

The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).

How do I clear my cache in GraphQL?

In your case, you can use the apollo's method client. resetStore(); It will clear the previous cache and then load the active queries.

How do you update the Apollo client cache after a mutation?

If a mutation updates a single existing entity, Apollo Client can automatically update that entity's value in its cache when the mutation returns. To do so, the mutation must return the id of the modified entity, along with the values of the fields that were modified.


1 Answers

Cleaning Unwanted Fields From GraphQL Responses

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

like image 157
Rigin Oommen Avatar answered Oct 17 '22 13:10

Rigin Oommen