apollo: Uncaught Invariant Violation: Schema type definitions not allowed in queries
Describe the bug
When using useQuery
, the following error occurs:
Uncaught Invariant Violation: Schema type definitions not allowed in queries. Found: "undefined"
at new InvariantError (webpack-internal:///./node_modules/ts-invariant/lib/invariant.esm.js:18:28)
at eval (webpack-internal:///./node_modules/@apollo/client/utilities/graphql/getFromAST.js:20:29)
at Array.map (<anonymous>)
at checkDocument (webpack-internal:///./node_modules/@apollo/client/utilities/graphql/getFromAST.js:18:10)
at getOperationDefinition (webpack-internal:///./node_modules/@apollo/client/utilities/graphql/getFromAST.js:28:5)
at getQueryDefinition (webpack-internal:///./node_modules/@apollo/client/utilities/graphql/getFromAST.js:42:20)
at StoreReader.diffQueryAgainstStore (webpack-internal:///./node_modules/@apollo/client/cache/inmemory/readFromStore.js:79:290)
at InMemoryCache.diff (webpack-internal:///./node_modules/@apollo/client/cache/inmemory/inMemoryCache.js:142:33)
at QueryInfo.getDiff (webpack-internal:///./node_modules/@apollo/client/core/QueryInfo.js:89:31)
at ObservableQuery.getCurrentResult (webpack-internal:///./node_modules/@apollo/client/core/ObservableQuery.js:99:39)
To Reproduce
const { result, error } = useQuery(
gql`
query {
viewer {
username
}
}
`,
null,
{ prefetch: false }
)
Expected behavior The query should not throw an uncaught error and should work. Calling the query manually works fine:
const { client } = useApolloClient()
if (process.client) {
client
.query({
query: gql`
query {
viewer {
username
}
}
`
})
.then(console.dir)
.catch(console.error)
}
Versions vue: 2.6.14 @vue/apollo-composable: 4.0.0-alpha.16 @vue/apollo-ssr: 4.0.0-alpha.16 @apollo/client: 3.5.9
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 15
Commits related to this issue
- fix: initialize currentDocument early, fix #1325 — committed to jnoordsij/vuejs-apollo by Akryum a year ago
I think the problem is graphql 16.x. Downgrading to 15.8 makes it work. Not sure what the problem with 16.x is though.
I’ve found thru debugging… the workaround is to call markRaw with the DocumentNode so that reactivity does not mutate the query.
Finally figured it out. Because the project I’m working on is using graphql codgen, the solution was incredibly easy with this wrapper:
And this change to codegen.ts:
Thank you @shenie and @xavxyz for your solutions!
I just came here to say that I have exactly the same issue. I tried converting a vue 2.7 / GraphQL 16.6 app from
vue-apollo
to@vue/apollo-composable
, both using the very sameapolloClient
instance (“@apollo/client”: “^3.7.11”`).Everything works fine using the older
vue-apollo
package, but when I try making the very same query with@vue/apollo-composable
, I get the familiar “Invalid AST Node” error (see #1372). Once I downgrade GraphQL to version 15.8, everything works again, even with@vue/apollo-composable
.Was anybody able to resolve this issue?
EDIT: Problem still present with the latest v4.0.0-beta.7.
I just tried this with beta.5 and I still have the problem when using graphql 16.6.0 @Akryum
Still present in Vue 2.7.14 and Graphql 16.16.0