Last active
January 4, 2021 04:28
-
-
Save trmaphi/0e0957d7b7de532c06c26e85a582bbf0 to your computer and use it in GitHub Desktop.
Tracing GraphQL resolvers with X-Ray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceResolvers from '@lifeomic/graphql-resolvers-xray-tracing'; | |
// Apply tracing middleware if running Lambda environment | |
if (process.env.AWS_LAMBDA_FUNCTION_NAME) { | |
traceResolvers(schema); | |
} | |
const apolloServer = new ApolloServer({ | |
schema, | |
context: contextFn, | |
introspection: true, | |
// https://github.com/apollographql/apollo-server/issues/1433#issuecomment-497074497 | |
formatError, | |
}); | |
const apolloHandler = apolloServer.createHandler({ | |
cors: { | |
origin: '*', | |
credentials: true, | |
}, | |
}); | |
export const handler = async (event: APIGatewayProxyEvent, context: Context) => { | |
AWSXRay.captureHTTPsGlobal(require('https'), true); | |
AWSXRay.capturePromise(); | |
return await new Promise((resolve, reject) => { | |
const callback: APIGatewayProxyCallback = (error, body) => (error ? reject(error) : resolve(body)); | |
apolloHandler(event, context, callback); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment