Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apollo-server-integrations/apollo-server-integration-cloudflare-workers
An integration to use Cloudflare Workers as a hosting service with Apollo Server
https://github.com/apollo-server-integrations/apollo-server-integration-cloudflare-workers
apollo cloudflare cloudflare-workers graphql hacktoberfest
Last synced: 2 months ago
JSON representation
An integration to use Cloudflare Workers as a hosting service with Apollo Server
- Host: GitHub
- URL: https://github.com/apollo-server-integrations/apollo-server-integration-cloudflare-workers
- Owner: apollo-server-integrations
- License: mit
- Created: 2022-12-30T02:30:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T21:41:46.000Z (3 months ago)
- Last Synced: 2024-10-29T23:47:25.596Z (3 months ago)
- Topics: apollo, cloudflare, cloudflare-workers, graphql, hacktoberfest
- Language: TypeScript
- Homepage: https://github.com/kimyvgy/worker-apollo-server-template
- Size: 1.56 MB
- Stars: 16
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @as-integrations/cloudflare-workers
[![NPM version](https://img.shields.io/npm/v/@as-integrations/cloudflare-workers.svg)](https://www.npmjs.com/package/@as-integrations/cloudflare-workers)
An integration to use Cloudflare Workers as a hosting service with Apollo Server.
## Quickstart
- Read the step-by-step tutorial: https://viblo.asia/p/y37Ldv3y4ov
- Checkout the repository template: https://github.com/kimyvgy/worker-apollo-server-template
- Live demo: https://worker-apollo-server.ds101.workers.dev## Install
```bash
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`:
```toml
node_compat = true # add this
``````typescript
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({
typeDefs,
resolvers,
introspection: true,
plugins: [
ApolloServerPluginLandingPageLocalDefault({ footer: false }),
],
});export interface Env {
// ...
}export default {
fetch: startServerAndCreateCloudflareWorkersHandler(server, {
context: async ({ env, request, ctx }) => {
return { token: 'secret' };
},
}),
};
```