Getting TypeError when Node is a selection set
kvithana opened this issue · 1 comments
kvithana commented
Getting this error when trying to codegen with a operation which does not have a name.
After looking into the code it looks like it's to do with trying to access node.name.value
to define operationName but if the operation was not declared with a name, node.name
will return undefined.
By giving the operation a name this error goes away.
TypeError: Cannot read property 'value' of undefined
at ApolloNextSSRVisitor._buildOperationPageQuery (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/bu
ild/src/visitor.js:74:58)
at ApolloNextSSRVisitor.buildOperation (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/build/src/vi
sitor.js:140:36)
at ApolloNextSSRVisitor.OperationDefinition (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/visitor-plugin-common/
index.cjs.js:2413:33)
at Object.visit (/Users/kalana/projects/musictaste-spaces/node_modules/graphql/language/visitor.js:243:26)
at Object.plugin (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/build/src/index.js:29:35)
at executePlugin (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:38:35)
at async /Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:116:24
at async Promise.all (index 1)
at async Object.codegen (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:106:20)
at async process (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/cli/bin.js:975:56)
TypeError: Cannot read property 'value' of undefined
at ApolloNextSSRVisitor._buildOperationPageQuery (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/bu
ild/src/visitor.js:74:58)
at ApolloNextSSRVisitor.buildOperation (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/build/src/vi
sitor.js:140:36)
at ApolloNextSSRVisitor.OperationDefinition (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/visitor-plugin-common/
index.cjs.js:2413:33)
at Object.visit (/Users/kalana/projects/musictaste-spaces/node_modules/graphql/language/visitor.js:243:26)
at Object.plugin (/Users/kalana/projects/musictaste-spaces/node_modules/graphql-codegen-apollo-next-ssr/build/src/index.js:29:35)
at executePlugin (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:38:35)
at async /Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:116:24
at async Promise.all (index 1)
at async Object.codegen (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/core/index.cjs.js:106:20)
at async process (/Users/kalana/projects/musictaste-spaces/node_modules/@graphql-codegen/cli/bin.js:975:56)
I managed to fix the error by passing in the node directly instead of trying to pass a string to the this.convertName
function. This results in the operationName
becoming Unnamed
which I think is the expected behaviour without crashing.
correttojs commented
thanks for the contribution!