-
Notifications
You must be signed in to change notification settings - Fork 29
isIntrospectionQuery assumes selection.name always exists #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@zachanator070 sorry for your troubles. Do you mind posting a minimal reproduction case please? I think our schemas are too simple for this to be triggered |
I found that you don't need a federated schema to replicate the issue. You just need a basic Apollo Server setup. Here is a repo that you can easily use: https://github.com/zachanator070/newrelic-apollo-plugin-demo Just run the app and then you can use this query to trigger the issue: |
Thanks! I'll take a look and make a fix with a corresponding test. |
@zachanator070 7.0.1 has been released with a fix for this reported issue. |
isIntrospectionQuery from lib/utils.js assumes selection.name always exists. This is not the case however in instances where a selection is a fragments that has a directive added to it.
Description
While using a federated Apollo graph schema, using any directive on a subgraph schema fragment causes the Apollo server plugin provided by the @newrelic/apollo-server-plugin npm package to crash with the following error:
TypeError: Cannot read properties of undefined (reading 'value')
at /usr/src/node-app/node_modules/@newrelic/apollo-server-plugin/lib/utils.js:15:38
at Array.every ()
at isIntrospectionQuery (/usr/src/node-app/node_modules/@newrelic/apollo-server-plugin/lib/utils.js:14:44)
at shouldIgnoreTransaction (/usr/src/node-app/node_modules/@newrelic/apollo-server-plugin/lib/utils.js:34:46)
at didResolveOperation (/usr/src/node-app/node_modules/@newrelic/apollo-server-plugin/lib/hooks.js:109:7)
at /usr/src/node-app/node_modules/@apollo/server/src/requestPipeline.ts:326:32
at Array.map ()
at processGraphQLRequest (/usr/src/node-app/node_modules/@apollo/server/src/requestPipeline.ts:325:24)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at internalExecuteOperation (/usr/src/node-app/node_modules/@apollo/server/src/ApolloServer.ts:1331:12)
at runHttpQuery (/usr/src/node-app/node_modules/@apollo/server/src/runHttpQuery.ts:232:27)
at runPotentiallyBatchedHttpQuery (/usr/src/node-app/node_modules/@apollo/server/src/httpBatching.ts:85:12)
at ApolloServer.executeHTTPGraphQLRequest (/usr/src/node-app/node_modules/@apollo/server/src/ApolloServer.ts:1106:14)
Expected Behavior
The plugin should allow the query to continue to execute and recognize that it is not an introspection query.
The isIntrospectionQuery function is called by the plugin's hook function didResolveOperation. This function is passed a requestContext object of this type from the Apollo server. The operation is of type OperationDefinitionNode but the name attribute on this type is optional. The
newrelic-node-apollo-server-plugin
should be able to handle the case when this attribute is not present.Troubleshooting or NR Diag results
The bug occurs when using the following directives on a fragment selection:
@defer
@include
@if
Steps to Reproduce
Pass an operation object with a
selectionSet.selections
attribute containing a selection set without aname
attribute.Your Environment
NodeJS version: v20.9.0
newrelic
npm package version: 11.17.0@newrelic/newrelic-node-apollo-server-plugin
npm package version: 6.0.0graphql
npm package version: 16.9.0The text was updated successfully, but these errors were encountered: