n1ru4l / envelop

Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
https://envelop.dev
MIT License
792 stars 129 forks source link

Cannot read properties of undefined (reading 'hrtime') #1771

Open pablocompagni-contractorvp opened 1 year ago

pablocompagni-contractorvp commented 1 year ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug

I get following error when I include apollo-tracing: Cannot read properties of undefined (reading 'hrtime')

Here's the more complete stack trace:

TypeError: Cannot read properties of undefined (reading 'hrtime')
    at file:///Users/user/Documents/work/projects/some_project/node_modules/@envelop/apollo-tracing/esm/index.js:31:53
    at field.resolve (file:///Users/user/Documents/work/projects/some_project/node_modules/@envelop/on-resolve/esm/index.js:18:56)
    at resolveField (/Users/user/Documents/work/projects/some_project/node_modules/graphql/execution/execute.js:464:18)
    at executeFields (/Users/user/Documents/work/projects/some_project/node_modules/graphql/execution/execute.js:292:18)
    at executeOperation (/Users/user/Documents/work/projects/some_project/node_modules/graphql/execution/execute.js:236:122)
    at executeImpl (/Users/user/Documents/work/projects/some_project/node_modules/graphql/execution/execute.js:116:14)
    at execute (/Users/user/Documents/work/projects/some_project/node_modules/graphql/execution/execute.js:60:35)
    at graphqlMiddleware (/Users/user/Documents/work/projects/some_project/node_modules/express-graphql/index.js:125:32)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  locations: [ { line: 4, column: 3 } ],
  path: [ 'deals' ]
}

It seems to be failling here, with ctx being undefined for some reason.

image

This is an ESM nodejs project, in case it matters.

Environment:

jdolle commented 7 months ago

I'm encountering this issue for our graphql subscriptions. It seems onExecute isnt called when executing a graphql subscription, but the onResolve function is still being called for the subscription field.

Also heads up that the link in the codebase for this plugin is not available any longer (https://github.com/apollographql/apollo-server/blob/main/packages/apollo-tracing/src/index.ts)

EmrysMyrddin commented 6 months ago

Yes, it seems that this plugin was not made with subscriptions in mind. Th fix would be to replicate the logic of the onExecute hook in the onSubscribe hook. Since subscriptions and simple queries are not using the same executor in graphql-js, Envelop offers 2 seperated hooks for the tow kind of operations.