I try to make a GraphQl mutation using apollo graphQl client.
This makes an error 500
when the mutation variables contains ___typename
properties (which obviously don't exist in the graphQl schema).
To fix that it is possible to set addTypename: false
in the graphQl client config:
const graphqlClient = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache({
addTypename: false
})
})
Now the mutation almost works…
But there is a new error: 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 Client can accurately match fragments.
So how should the graphQl client be configured to handle mutations?
for now I use a cleanup function found here:
const removeTypename = (value) => {
if (value === null || value === undefined) {
return value;
} else if (Array.isArray(value)) {
return value.map(v => removeTypename(v));
} else if (typeof value === 'object') {
const newObj = {};
Object.keys(value).forEach(key => {
if (key !== '__typename') {
newObj[key] = removeTypename(value[key]);
}
});
return newObj;
}
return value;
};
but it feels hacky. Is there something built-in graphql client?
__typename
field. – Daniel Rearden___typename
were added from a previous query – François Romain