graphql-query-complexity icon indicating copy to clipboard operation
graphql-query-complexity copied to clipboard

GQL causes TypeError: "Cannot read properties of undefined (reading 'name')"

Open sam-super opened this issue 1 year ago • 2 comments

This query was in some logs:

mutation { 
  __typename 
}

which caused:

TypeError: Cannot read properties of undefined (reading 'name')\n    at QueryComplexity.nodeComplexity (/app/node_modules/graphql-query-complexity/dist/cjs/QueryComplexity.js:105:46

sam-super avatar Nov 25 '22 09:11 sam-super

Are mutations configured in the schema of the GraphQL server? Might be the same issue as this one: https://github.com/slicknode/graphql-query-complexity/pull/84

ivome avatar Dec 14 '22 22:12 ivome

We are having the same (similar) issue. Even if the operation is defined in GraphQL schema but you don't give your actual query a name then it will issue the type error.

For example:

mutation {
	doSomething(input: { amount: 1 }) {
		result
	}
}

will error but

mutation myOperation {
	doSomething(input: { amount: 1 }) {
		result
	}
}

will not.

We are on Apollo 3 and GraphQL (graphql package) 15

abjrcode avatar Jan 13 '23 15:01 abjrcode