/apollo-server-vercel

⚫ Production-ready Node.js GraphQL server for Vercel Serverless Functions

Primary LanguageTypeScriptMIT LicenseMIT

⚫ Apollo Server Vercel

npmtraviscodecov

Production-ready Node.js GraphQL server for Vercel Serverless Functions.


Note: These docs are subject to change, as this library is under construction. Expect things to be broken!

📦 Installation

npm install --save @saeris/apollo-server-vercel graphql
# or
yarn add @saeris/apollo-server-vercel graphql

🔧 Usage

import { ApolloServer } from "@saeris/apollo-server-vercel";

// Construct a schema, using GraphQL schema language
const typeDefs = `
  type Query {
    hello: String
  }
`;

// Provide resolver functions for your schema fields
const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,

  // By default, the GraphQL Playground interface and GraphQL introspection
  // is disabled in "production" (i.e. when `process.env.NODE_ENV` is `production`).
  //
  // If you'd like to have GraphQL Playground and introspection enabled in production,
  // the `playground` and `introspection` options must be set explicitly to `true`.
  playground: true,
  introspection: true,
});

export default server.createHandler();

🕹️ Demo

The example under api/example.ts is live at https://apollo-server-vercel.saeris.io/api/example. You can also give it a try via CodeSandbox or locally by cloning this repo, running yarn && yarn start, and then navigate to the URL provided in your terminal (usually http://localhost:3000/api/example).

🧪 Testing

Testing is provided via jest and is pre-configured to run with codecov as well. Tests for this project have been adapted from the official Apollo Server integration tests and they can be found under src/__test__. Additionally, this project uses eslint, typescript, and prettier, all three of which are automatically run on each commit via husky + lint-staged. To manually lint and test, use the following commands:

Lint:

yarn lint

Typecheck:

yarn typecheck

Test and watch for changes:

yarn test:watch

Lint + Typecheck + Test:

yarn test

🥂 License

Released under the MIT license.