1.0.2 • Published 1 month ago

@as-integrations/cloudflare-workers v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@as-integrations/cloudflare-workers

NPM version

An integration to use Cloudflare Workers as a hosting service with Apollo Server.

Quickstart

Install

npm add @apollo/server @as-integrations/cloudflare-workers graphql

Usage

You must enable Node.js compatibility feature by adding the following flag in the file wrangler.toml:

node_compat = true  # add this
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateCloudflareWorkersHandler } from '@as-integrations/cloudflare-workers';
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';

const typeDefs = `#graphql
  type Query {
    example: String!
  }
`;

const resolvers = {
  Query: {
    example: () => {
      return 'Hello universe!';
    },
  }
}

interface Context {
  token: string
}

const server = new ApolloServer<Context>({
  typeDefs,
  resolvers,
  introspection: true,
  plugins: [
    ApolloServerPluginLandingPageLocalDefault({ footer: false }),
  ],
});

export interface Env {
  // ...
}

export default {
  fetch: startServerAndCreateCloudflareWorkersHandler<Env, Context>(server, {
    context: async ({ env, request, ctx }) => {
      return { token: 'secret' };
    },
  }),
};
1.0.2

1 month ago

1.0.1

1 month ago

1.0.0

1 month ago

1.0.0-alpha

1 month ago

0.2.0

7 months ago

0.1.1

1 year ago

0.1.0

1 year ago