Vercel Serverless Integration#
Install#
yarn add graphql graphql-ez @graphql-ez/vercel
yarn add -D @vercel/node @types/nodepnpm add graphql graphql-ez @graphql-ez/vercel
pnpm add -D @vercel/node @types/nodenpm install graphql graphql-ez @graphql-ez/vercel
npm install -D @vercel/node @types/nodeUsage#
Server module /api/graphql.ts
import { ezApp } from '../src/ez';
const { apiHandler } = ezApp.buildApp();
export default apiHandler;
EZ App module /src/ez.ts
import { CreateApp, gql } from '@graphql-ez/vercel';
export const ezApp = CreateApp({
  // You can use any valid GraphQL Schema
  schema,
  ez: {
    plugins: [
      // EZ Plugins
    ],
  },
  envelop: {
    plugins: [
      // Envelop Plugins
    ],
  },
  // Other Options
});
Build Custom Context#
import { CreateApp, VercelContextArgs, InferContext } from '@graphql-ez/vercel';
function buildContext({ req, vercel }: VercelContextArgs) {
  // IncomingMessage
  req;
  // VercelRequest
  vercel.req;
  return {
    foo: 'bar',
  };
}
// This snippet allows you to infer the context returned by your 'buildContext' and add it to the EZContext interface
declare module 'graphql-ez' {
  interface EZContext extends InferContext<typeof buildContext> {}
}
export const ezApp = CreateApp({
  // ...
  buildContext,
});
Cross-Origin Resource Sharing (CORS)#
To enable CORS, specify the cors property in your configuration
CreateApp({
  cors: true,
});
Check the cors package for all the available options.
CreateApp({
  // Check https://npm.im/cors#configuration-options
  cors: {
    // ...
  },
});