How to use the apollo-server-lambda.graphqlLambda function in apollo-server-lambda

To help you get started, we’ve selected a few apollo-server-lambda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / serverless-graphql / app-backend / dynamodb / handler.js View on Github external
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);
};
github abernix / serverless-graphql-lambda-simple / functions / helpers.js View on Github external
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);
  }
}
github freeCodeCamp / open-api / src / handler.js View on Github external
/* 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();
github serverless / serverless-graphql / app-backend / rds / handler.js View on Github external
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);
};
github prisma-labs / graphql-playground / packages / graphql-playground-middleware-lambda / examples / basic / handler.js View on Github external
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)
}
github muriloamendola / graphql-serverless / src / handler.js View on Github external
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);
  };
github serverless / serverless-graphql / app-backend / rest-api / handler.js View on Github external
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);
};
github prisma-labs / graphql-yoga / src / lambda.ts View on Github external
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') {
github back4app / antframework / plugins / ant-serverless / templates / serverless / default / graphQL.js View on Github external
}
          }
        }
      );
    }));
  };
});

const graphQL = ant.pluginController.getPlugin('GraphQL');

const schema = schemaHelper.generateSchema(
  ant,
  graphQL
);

exports.run = graphqlLambda({
  schema
});

apollo-server-lambda

Production-ready Node.js GraphQL server for AWS Lambda

MIT
Latest version published 7 months ago

Package Health Score

85 / 100
Full package analysis