worker-apollo-server
v0.0.0
Published
A template for kick starting a Cloudflare worker project to deploy Apollo Server v4 to Cloudflare Workers.
Downloads
4
Readme
👷 worker-apollo-server
Quick start
A template for kick starting a Cloudflare worker project to deploy Apollo Server v4 to Cloudflare Workers.
index.ts
is the content of the Workers script.
handlers/apollo.ts
: Route handler for GraphQL query request- kimyvgy/apollo-server-integration-cloudflare-workers
- Enable Playground / Sandbox by adding
plugins
+introspection
:
const server = new ApolloServer<ContextValue>({
typeDefs,
resolvers,
introspection: true,
plugins: [
ApolloServerPluginLandingPageLocalDefault({ footer: false }),
// ApolloServerPluginLandingPageProductionDefault({
// graphRef: 'my-graph-id@my-graph-variant',
// footer: false,
// })
],
});
Example
Live: https://worker-apollo-server.webee-asia.workers.dev
query {
example
pokemon(id: 1) {
id
name
}
}
Response:
{
"data": {
"example": "Hello world!",
"pokemon": {
"id": "1",
"name": "bulbasaur"
}
}
}
Development
Click Use this template button to create your own repository.
Start your dev server with following commands:
yarn install
yarn dev
Open up http://0.0.0.0:8787 and you should be ready to go!
This template uses
graphql-codegen
to auto-generate Typescript types fromschema.graphql
. The types are generated to filesrc/@types/schema.generated.ts
. So you can import Resolver Types from there.
Deployment
If you don't already have an account, then create a cloudflare account here and after verifying your email address with Cloudflare, go to your dashboard and set up your free custom Cloudflare Workers subdomain.
Once that's done, you should be able to deploy your app:
yarn deploy
yarn run v1.22.19
$ wrangler publish
⛅️ wrangler 2.1.9
-------------------
Running custom build: npm run generate && npm run build
> generate
> graphql-codegen --config codegen.yml
✔ Parse Configuration
✔ Generate outputs
> build
> NODE_ENV=production node worker.build.js
Your worker has access to the following bindings:
- KV Namespaces:
- GRAPHQL_CACHE: dbdc624f2c684f1bb88fa38ab249a13e
- Vars:
- GRAPHQL_BASE_ENDPOINT: "/"
- GRAPHQL_KV_CACHE: "true"
Total Upload: 1520.16 KiB / gzip: 285.68 KiB
Uploaded worker-apollo-server (2.71 sec)
Published worker-apollo-server (0.28 sec)
https://worker-apollo-server.webee-asia.workers.dev
Done in 7.29s.