How to use the apollo-server-lambda.ApolloServer 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 hasura / graphql-serverless / aws-lambda-nodejs / src / graphql.js View on Github external
content: content,
                    author_id: author_id
                });
                return article;
            } catch (e) {
                console.log(e);
                throw new Error(e);
            }
        }
    }
};

// In the most basic sense, the ApolloServer can be started
// by passing type definitions (typeDefs) and the resolvers
// responsible for fetching the data for those types.
const server = new ApolloServer({
    typeDefs,
    resolvers,
    context: ({ event, context }) => ({
        headers: event.headers,
        functionName: context.functionName,
        event,
        context,
    }),
});

exports.handler = server.createHandler({
    cors: {
        origin: '*',
        credentials: true,
        allowedHeaders: 'Content-Type, Authorization'
    },
github Brikl / serverless-apollo-datasource-redis / handler.js View on Github external
type Doc @cacheControl(maxAge: 6000) {
    web_url: String
    snippet: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    searchNYTimes: async (_source, { q }, { dataSources }) => {
      return dataSources.nytimesAPI.searchNYArticle(q);
    }    
  }
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  tracing: true,
  cacheControl: {
    defaultMaxAge: 5,
    stripFormattedExtensions: false,
    calculateCacheControlHeaders: false,
  },
  dataSources: () => {
    return {
      nytimesAPI: new NYTIMESAPI(),
    };
  },  
  cache: new RedisCache({
    connectTimeout: 5000,
    reconnectOnError: function (err) {
github anttiviljami / serverless-type-graphql-boilerplate / src / handler.ts View on Github external
synchronize: true,
      logger: 'advanced-console',
      logging: 'all',
      dropSchema: true,
      cache: true,
    });
  }

  // build TypeGraphQL executable schema
  (global as any).schema = (global as any).schema || await TypeGraphQL.buildSchema({
    resolvers: [RecipeResolver, RateResolver],
    validate: false,
  });
  const schema = (global as any).schema;

  const server = new ApolloServer({ schema });
  server.createHandler()(event, context, callback);
}
github netlify / cli / src / functions-templates / js / apollo-graphql / apollo-graphql.js View on Github external
return 'Hello, world!'
    },
    allAuthors: (root, args, context) => {
      return authors
    },
    author: (root, args, context) => {
      return
    },
    authorByName: (root, args, context) => {
      console.log('hihhihi', args.name)
      return authors.find(x => x.name === args.name) || 'NOTFOUND'
    }
  }
}

const server = new ApolloServer({
  typeDefs,
  resolvers
})

exports.handler = server.createHandler()
github netlify / netlify-dev-plugin / src / functions-templates / js / apollo-graphql-rest / apollo-graphql-rest.js View on Github external
It's multiline and you can use **markdown**!
    """
    getUser(gender: String): User
    getUsers(people: Int, gender: String): [User]
  }
`;
const resolvers = {
  Query: {
    getUser: async (_, { gender }, { dataSources }) =>
      dataSources.RandomUser.getUser(gender),
    getUsers: async (_, { people, gender }, { dataSources }) =>
      dataSources.RandomUser.getUsers(people, gender)
  }
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    RandomUser: new RandomUser()
  })
});

exports.handler = server.createHandler();
github lowsky / dashboard / server / src / lambda / graphql.ts View on Github external
import { ApolloServer } from 'apollo-server-lambda';

import { schema } from '../../localSchema';

const server = new ApolloServer({
    schema,
    introspection: true,
    playground: true,
});

exports.handler = server.createHandler({});
github webiny / webiny-js / packages / demo-api-gateway / src / handler.js View on Github external
export const handler = async (event, context) => {
    const config = await createConfig();
    const { schema, executor } = await gateway.load();

    const apollo = new ApolloServer({
        ...(config.apollo || {}),
        schema,
        executor,
        introspection: true,
        playground: true,
        context: async ({ event }) => {
            return { headers: event.headers };
        }
    });

    const handler = apollo.createHandler();

    return new Promise((resolve, reject) => {
        handler(event, context, (error, data) => {
            if (error) {
                return reject(error);
github webiny / webiny-js / packages / webiny-api / src / lambda / lambda.js View on Github external
}

        for (let i = 0; i < ctxPlugins.length; i++) {
            if (typeof ctxPlugins[i].apply === "function") {
                await ctxPlugins[i].apply(context);
            }
        }

        for (let i = 0; i < ctxPlugins.length; i++) {
            if (typeof ctxPlugins[i].postApply === "function") {
                await ctxPlugins[i].postApply(context);
            }
        }
    });

    const apollo = new ApolloServer({
        ...(config.apollo || {}),
        schema,
        cors: {
            origin: "*",
            methods: "GET,HEAD,POST"
        },
        context: async ({ event }) => {
            await requestSetup(config);

            return {
                event,
                config,
                getDatabase() {
                    return config.database.mongodb;
                }
            };
github tomyitav / apollo-typed-lambda / src / server.ts View on Github external
private createApolloServer() {
    const graphqlRoutePrefix = process.env.IS_OFFLINE ? '' : '/dev'
    this.apolloServer = new ApolloServer({
      schema,
      context: this.context,
      playground: {
        endpoint: graphqlRoutePrefix + '/graphql'
      }
    })
  }
}
github netlify / netlify-dev-plugin / src / functions-templates / js / graphql-gateway / example-sibling-function-graphql-1.js View on Github external
hello: (root, args, context) => {
      return "Hello, world!";
    },
    allAuthors: (root, args, context) => {
      return authors;
    },
    author: (root, args, context) => {
      return;
    },
    authorByName: (root, args, context) => {
      return authors.find(x => x.name === args.name) || "NOTFOUND";
    }
  }
};

const server = new ApolloServer({
  typeDefs,
  resolvers
});

exports.handler = server.createHandler();

apollo-server-lambda

Production-ready Node.js GraphQL server for AWS Lambda

MIT
Latest version published 12 months ago

Package Health Score

67 / 100
Full package analysis