Skip to content

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

Closed
zachanator070 opened this issue Apr 18, 2025 · 5 comments · Fixed by #341
Closed

isIntrospectionQuery assumes selection.name always exists #340

zachanator070 opened this issue Apr 18, 2025 · 5 comments · Fixed by #341
Assignees
Labels
bug Something isn't working points:3

Comments

@zachanator070
Copy link

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 a name 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.0
graphql npm package version: 16.9.0

@zachanator070 zachanator070 added bug Something isn't working needs-triage labels Apr 18, 2025
@workato-integration
Copy link

@bizob2828
Copy link
Member

bizob2828 commented Apr 21, 2025

@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

@zachanator070
Copy link
Author

zachanator070 commented Apr 21, 2025

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:

Image

@bizob2828
Copy link
Member

Thanks! I'll take a look and make a fix with a corresponding test.

@bizob2828 bizob2828 self-assigned this Apr 21, 2025
@bizob2828 bizob2828 moved this from Triage Needed: Unprioritized Features to Needs PR Review in Node.js Engineering Board Apr 21, 2025
@github-project-automation github-project-automation bot moved this from Needs PR Review to Done: Issues recently completed in Node.js Engineering Board Apr 21, 2025
@bizob2828
Copy link
Member

@zachanator070 7.0.1 has been released with a fix for this reported issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working points:3
Projects
Status: Done: Issues recently completed
2 participants