Does anyone have any idea how do I use fragments on unions? I've seen the documentation for React (https://www.apollographql.com/docs/react/advanced/fragments/#fragments-on-unions-and-interfaces) but not much on Vue. I have a query that returns two fragments, both with __typename.
query {
search(queryString: "lin") {
... on Professor {
__typename
name
}
... on Course {
__typename
name
moduleCode
}
}
}
When the vue app runs, I received the 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." This is the code from my vue app.
data() {
return {
result: []
};
},
apollo: {
// Query with parameters
result: {
// gql query
query: gql'
query search($queryString: String!) {
... on Professor {
__typename
name
}
... on Course {
__typename
name
moduleCode
}
}
',
// Static parameters
variables() {
return {
queryString: 'lin mei'
}
}
}
},
// In my apollo client options
// Override default cache
cache: new InMemoryCache(
{ addTypename: true }
}
The error messages I got are
- 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.
- 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.
- GraphQL error: Fragment on Professor can't be spread inside Query; GraphQL error: Fragment on Course can't be spread inside Query; GraphQL error: Variable $queryString is declared by search but not used
- GraphQL error: Fragment on Professor can't be spread inside Query; GraphQL error: Fragment on Course can't be spread inside Query; GraphQL error: Variable $queryString is declared by search but not used
Is anyone able to provide an example of grabbing two fragments from a query in vue?
__typename
automatically (addTypename
istrue
by default). There's no need to explicitly add__typename
to your query, or to set the option. – Daniel Rearden