Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { graphqlLambda, graphiqlLambda } = require('apollo-server-lambda');
const myGraphQLSchema = require('./graphql/schema');
const graphqlHandler = graphqlLambda({ schema: myGraphQLSchema });
const graphiqlHandler = graphiqlLambda({ endpointURL: 'http://localhost:3000/graphql' });
module.exports = {
graphqlHandler,
graphiqlHandler
};
// Avoid CORS problem when using Angular Apollo Client for example
/* const graphqlHandler = (event, context, callback) => {
const callbackFilter = (error, output) => {
output.headers['Access-Control-Allow-Origin'] = '*';
callback(error, output);
};
const handler = graphqlLambda({ schema: myGraphQLSchema });
logger: console,
});
exports.graphqlHandler = function graphqlHandler(event, context, callback) {
function callbackFilter(error, output) {
// eslint-disable-next-line no-param-reassign
output.headers['Access-Control-Allow-Origin'] = '*';
callback(error, output);
}
const handler = graphqlLambda({ schema: myGraphQLSchema });
return handler(event, context, callbackFilter);
};
// for local endpointURL is /graphql and for prod it is /stage/graphql
exports.graphiqlHandler = graphiqlLambda({
endpointURL: process.env.REACT_APP_GRAPHQL_ENDPOINT
? process.env.REACT_APP_GRAPHQL_ENDPOINT
: '/production/graphql',
});
// for local endpointURL is /graphql and for prod it is /stage/graphql
exports.playgroundHandler = lambdaPlayground({
endpoint: process.env.REACT_APP_GRAPHQL_ENDPOINT
? process.env.REACT_APP_GRAPHQL_ENDPOINT
: '/production/graphql',
});
const { graphiqlLambda } = require('apollo-server-lambda');
exports.run = graphiqlLambda({
endpointURL: '/dev/graphql',
});