Throughout my code I use fragments to break up the data requirements. However, in the header I have a simple query:
query: gql`
query HeaderUser {
me {
nameFirst
nameLast
}
}
`
Sometimes this Query returns null ({ me: null }) and Apollo Client raises a really annoying error each time: 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. and Could not find __typename on Fragment Query {me: null}. This is really weird because I am not even using fragments in this case. Is there a way to remove this error?
Version
EDIT
I would also like to add that the error comes up on some responses that even do contain the __fragment field.
You should make sure that every query you're writing includes id field and that you haven't set addTypename: false option for apollo client.
My guess is that you're probably fetching a user/profile (or whatever the type for me query is) in some query other than me without id and that apollo cache gets confused because it can't normalize state without ids.
I suggest rewriting this query to
query: gql`
query HeaderUser {
me {
id
nameFirst
nameLast
}
}
`
and then add id to every query (and also to every field and subfield of every query) used in the app even if you're not explicitly using it.
The explanation outlined in https://github.com/apollographql/apollo-client/issues/3249#issuecomment-408583967 sounds quite reasonable. If that doesn't help, please provide a small runnable reproduction that clearly demonstrates this issue. Thanks!
Most helpful comment
You should make sure that every query you're writing includes
idfield and that you haven't setaddTypename: falseoption for apollo client.My guess is that you're probably fetching a user/profile (or whatever the type for
mequery is) in some query other thanmewithout id and that apollo cache gets confused because it can't normalize state without ids.I suggest rewriting this query to
and then add
idto every query (and also to every field and subfield of every query) used in the app even if you're not explicitly using it.