UNPKG

@graphql-mesh/http

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