Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
event.path.startsWith("/graphiql")) {
const endpointURL =
urlResolve(process.env.ENGINE_PROXY_URL, "/graphql");
return graphiqlLambda({ endpointURL })(...args);
}
const query = queryFromEvent(event);
// This forces the otherwise Lambda shaped query into what Apollo Server
// expects (it refuses to process it otherwise!)
event.httpMethod = 'POST';
event.body = JSON.stringify({ query });
return graphqlLambda(method)(...args);
}
}
/* eslint-enable max-len */
context.callbackWaitsForEmptyEventLoop = false;
function callbackFilter(error, output) {
if (!output.headers) {
output.headers = {};
}
// eslint-disable-next-line no-param-reassign
output.headers['Access-Control-Allow-Origin'] = '*';
output.headers['Access-Control-Allow-Credentials'] = true;
output.headers['Content-Type'] = 'application/json';
callback(error, output);
}
const handler = graphqlLambda((event, context) => {
const { headers } = event;
const { functionName } = context;
return {
schema: graphqlSchema,
context: {
headers,
functionName,
event,
context
}
};
});
try {
await connectToDatabase();
exports.graphqlHandler = function graphqlHandler(event, context, callback) {
context.callbackWaitsForEmptyEventLoop = false;
function callbackFilter(error, output) {
if (!output.headers) {
output.headers = {};
}
// eslint-disable-next-line no-param-reassign
output.headers['Access-Control-Allow-Origin'] = '*';
callback(error, output);
}
const handler = graphqlLambda({ schema: myGraphQLSchema, tracing: true });
return handler(event, context, callbackFilter);
};
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 myGraphQLSchema = makeExecutableSchema({ typeDefs, resolvers })
const handler = graphqlLambda({ schema: myGraphQLSchema })
return handler(event, context, callbackFilter)
}
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);
};
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);
};
if (
event.headers &&
event.headers['X-GraphQL-Deduplicate'] &&
response.data &&
!response.data.__schema
) {
response.data = deflate(response.data)
}
return this.options.formatResponse
? this.options.formatResponse(response, ...args)
: response
}
}
const handler = graphqlLambda(async (event, lambdaContext) => {
let apolloContext
try {
apolloContext =
typeof this.context === 'function'
? await this.context({
event,
context: lambdaContext,
fragmentReplacements: this.middlewareFragmentReplacements,
})
: this.context
} catch (e) {
console.error(e)
throw e
}
if (typeof this.options.validationRules === 'function') {
}
}
}
);
}));
};
});
const graphQL = ant.pluginController.getPlugin('GraphQL');
const schema = schemaHelper.generateSchema(
ant,
graphQL
);
exports.run = graphqlLambda({
schema
});