Skip to content

Instantly share code, notes, and snippets.

@trmaphi
Last active January 4, 2021 04:28
Show Gist options
  • Save trmaphi/0e0957d7b7de532c06c26e85a582bbf0 to your computer and use it in GitHub Desktop.
Save trmaphi/0e0957d7b7de532c06c26e85a582bbf0 to your computer and use it in GitHub Desktop.
Tracing GraphQL resolvers with X-Ray
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