Skip to content

Commit

Permalink
fix(graphql-server): Move yoga creation to avoid creation on every re…
Browse files Browse the repository at this point in the history
…quest (#9039)

**Problem**
v6 has seen some performance issues. These appear to have sneaked in on
#8339. This just reverts the change by moving the creation of the yoga
object so that it isn't created on every request.

**Changes**
1. Moves yoga creation.

**Outstanding**
1. We still have a tiny bit of work to do analysing a slight performance
decline since 4.4.3
  • Loading branch information
Josh-Walker-GM authored and thedavidprice committed Aug 15, 2023
1 parent 53a0987 commit 6f9fbfb
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions packages/graphql-server/src/functions/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ export const createGraphQLHandler = ({
schemaOptions,
openTelemetryOptions,
}: GraphQLHandlerOptions) => {
const { yoga, logger } = createGraphQLYoga({
healthCheckId,
loggerConfig,
context,
getCurrentUser,
onException,
generateGraphiQLHeader,
extraPlugins,
authDecoder,
cors,
services,
sdls,
directives,
armorConfig,
allowedOperations,
allowIntrospection,
allowGraphiQL,
defaultError,
graphiQLEndpoint,
schemaOptions,
openTelemetryOptions,
})

const handlerFn = async (
event: APIGatewayProxyEvent,
requestContext: LambdaContext
Expand All @@ -50,30 +73,6 @@ export const createGraphQLHandler = ({
requestContext.callbackWaitsForEmptyEventLoop = false

let lambdaResponse: APIGatewayProxyResult

const { yoga, logger } = createGraphQLYoga({
healthCheckId,
loggerConfig,
context,
getCurrentUser,
onException,
generateGraphiQLHeader,
extraPlugins,
authDecoder,
cors,
services,
sdls,
directives,
armorConfig,
allowedOperations,
allowIntrospection,
allowGraphiQL,
defaultError,
graphiQLEndpoint,
schemaOptions,
openTelemetryOptions,
})

try {
// url needs to be normalized
const [, rest = ''] = event.path.split(graphiQLEndpoint)
Expand Down

0 comments on commit 6f9fbfb

Please sign in to comment.