Skip to content

Commit

Permalink
fix(graphql-server): Improve GraphQL API performance by not accessing…
Browse files Browse the repository at this point in the history
… project config in makeMergedSchema (#9032)

**Problem**
The toml config is not always available in serverless deploy
environments and because `makeMergedSchema` is called on every request
(in such deploy environments) then throwing & catching a JS error causes
a heavy performance decrease.

**Changes**
1. Base the opentelemetry functionality on the graphql plugin options
alone.

**Notes**
1. Will have to update the experimental docs. You must disable both toml
and graphql options now as toml does not override/impact the
functionality.
  • Loading branch information
Josh-Walker-GM authored and jtoar committed Aug 11, 2023
1 parent 149bf1c commit f898d20
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/graphql-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@graphql-tools/utils": "10.0.1",
"@opentelemetry/api": "1.4.1",
"@redwoodjs/api": "6.0.5",
"@redwoodjs/project-config": "6.0.5",
"core-js": "3.31.1",
"graphql": "16.7.1",
"graphql-scalars": "1.22.2",
Expand All @@ -48,6 +47,7 @@
"@babel/core": "7.22.9",
"@envelop/testing": "6.0.0",
"@envelop/types": "4.0.0",
"@redwoodjs/project-config": "6.0.5",
"@redwoodjs/realtime": "6.0.5",
"@types/jsonwebtoken": "9.0.2",
"@types/lodash": "4.14.195",
Expand Down
15 changes: 1 addition & 14 deletions packages/graphql-server/src/makeMergedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import type {
} from 'graphql'
import { merge, omitBy } from 'lodash'

import { getConfig } from '@redwoodjs/project-config'

import type { RedwoodDirective } from './plugins/useRedwoodDirective'
import * as rootGqlSchema from './rootSchema'
import type { RedwoodSubscription } from './subscriptions/makeSubscriptions'
Expand Down Expand Up @@ -104,22 +102,11 @@ const mapFieldsToService = ({
context: unknown,
info: unknown
) => {
// In serverless deploys like Netilfy and Vercel, the redwood.toml file may not be present,
// so we need to try-catch the attempt here to read it
let experimentalOpenTelemetryEnabled = false

try {
experimentalOpenTelemetryEnabled =
getConfig().experimental.opentelemetry.enabled
} catch (e) {
// Swallow the error for now
}

const captureResolvers =
// @ts-expect-error context is unknown
context && context['OPEN_TELEMETRY_GRAPHQL'] !== undefined

if (experimentalOpenTelemetryEnabled && captureResolvers) {
if (captureResolvers) {
return wrapWithOpenTelemetry(
services[name],
args,
Expand Down

0 comments on commit f898d20

Please sign in to comment.