UNPKG

@graphql-mesh/http

Version:
32 lines (31 loc) 1.25 kB
import { createYoga, useLogger } from 'graphql-yoga'; export const graphqlHandler = ({ getBuiltMesh, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig, batchingLimit, }) => { let yoga$; return (request, ctx) => { if (!yoga$) { yoga$ = getBuiltMesh().then(mesh => createYoga({ plugins: [ ...mesh.plugins, useLogger({ skipIntrospection: true, logFn: (eventName, { args }) => { if (eventName.endsWith('-start')) { mesh.logger.debug(`\t headers: `, args.contextValue.headers); } }, }), ], logging: mesh.logger, maskedErrors: false, graphiql: playgroundEnabled && { title: playgroundTitle, }, cors: corsConfig, graphqlEndpoint, landingPage: false, batching: batchingLimit ? { limit: batchingLimit } : false, })); } return yoga$.then(yoga => yoga.handleRequest(request, ctx)); }; };