@graphql-mesh/http
Version:
43 lines (42 loc) • 1.68 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.graphqlHandler = void 0;
const graphql_yoga_1 = require("graphql-yoga");
const graphqlHandler = ({ getBuiltMesh, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig, batchingLimit, }) => {
let yoga;
let yoga$;
return (request, ctx) => {
if (yoga) {
return yoga.handleRequest(request, ctx);
}
if (!yoga$) {
yoga$ = getBuiltMesh().then(mesh => {
yoga = (0, graphql_yoga_1.createYoga)({
plugins: [
...mesh.plugins,
(0, graphql_yoga_1.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;
});
}
return yoga$.then(yoga => yoga.handleRequest(request, ctx));
};
};
exports.graphqlHandler = graphqlHandler;
;