Skip to content
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

Slow query execution when using @graphql-debugger/trace-schema #287

Open
knikoloski opened this issue Apr 25, 2024 · 1 comment
Open

Slow query execution when using @graphql-debugger/trace-schema #287

knikoloski opened this issue Apr 25, 2024 · 1 comment

Comments

@knikoloski
Copy link

Issue description

I'm experiencing slow query execution when using the @graphql-debugger/trace-schema package in my schema setup. My schema setup includes Nexus for defining the GraphQL schema and Prisma for database access.

Here's a simplified version of my setup:

import { makeSchema } from 'nexus'
import { paljs } from '@paljs/nexus'

import { traceSchema } from '@graphql-debugger/trace-schema'
import { ProxyAdapter } from '@graphql-debugger/adapter-proxy'

const nexusSchema = makeSchema({
  plugins: [paljs()],
  shouldExitAfterGenerateArtifacts: process.argv.includes('--nexus-typegen'),
  shouldGenerateArtifacts: process.argv.includes('--nexus-typegen'),
  types: [generatedTypes, types, GQLDate, NumberScalar, IdArray],
  outputs: {
    typegen: __dirname + '/generated/nexus.d.ts',
  },
  sourceTypes: {
    modules: [
      {
        module: '.prisma/client',
        alias: 'prisma',
      },
    ],
  },
})

const adapter = new ProxyAdapter()
export const schema = traceSchema({
  schema: nexusSchema,
  adapter,
  exporterConfig: {
    url: 'https://otlp.eu01.nr-data.net:4317/v1/traces',
    headers: {
      'Content-Type': 'application/json',
      'api-key': process.env.NEW_RELIC_LICENSE_KEY as string,
    },
  },
})

Here's a simple ping query that I have defined:

import { extendType } from 'nexus'

export const ping = extendType({
  type: 'Query',
  definition(t) {
    t.field('ping', {
      type: 'String',
      async resolve() {
        return 'pong'
      },
    })
  },
})

When I remove the traceSchema wrapper and export nexusSchema directly, query execution of the ping query is fast. However, with traceSchema, query ping takes more than 1 or 2 seconds to execute (it should not take more than 20 or 30 ms to execute).

Packages version:

@graphql-debugger/adapter-proxy: 0.0.0-alpha.100
@graphql-debugger/trace-schema: 0.0.0-alpha.100
Node.js version: 20.12.2
Prisma version: 5.10.2
Nexus version: 1.3.0

Additional information:

After debugging the traceSchema function directly in the node_modules/@graphql-debugger/trace-schema/build/trace-schema.js file, I found that removing the following block of code resolves the slowness issue:

FieldDefinition: {
    enter(node) {
        const existingTraceDirective = node.directives?.find((directive) => directive.name.value === "trace");
        if (existingTraceDirective) {
            return;
        }
        const newDirectives = [
            ...(node.directives ?? []),
            {
                kind: graphql_1.Kind.DIRECTIVE,
                name: {
                    kind: graphql_1.Kind.NAME,
                    value: "trace",
                },
            },
        ];
        return {
            ...node,
            directives: newDirectives,
        };
    },
},

Please let me know if you need any further information. Thank you for your help in resolving this issue.

@danstarns
Copy link
Member

@knikoloski thanks for reporting.

I just shipped 0.0.0-alpha.103

It allows you to pass the shouldExcludeTypeFields key to trace schema see more

Please try this option and report if you notice an improvement, in the mean time we will be working on benchmarks to better diagnose your described issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants