generated from kimyvgy/worker-typescript-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from kimyvgy/next
feat!: upgrade to @as-integrations/cloudflare-workers:^1.0.0
- Loading branch information
Showing
26 changed files
with
435 additions
and
4,631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
.vscode | ||
.yalc | ||
yalc.lock | ||
.wrangler | ||
.DS_Store | ||
/node_modules | ||
*-lock.* | ||
*.lock | ||
*.log | ||
|
||
build | ||
src/@types/schema.generated.ts | ||
node_modules | ||
.env | ||
|
||
# yarn.lock | ||
yarn-error.log | ||
package-lock.json | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"semi": true, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"insertPragma": false, | ||
"requirePragma": false, | ||
"jsxSingleQuote": false, | ||
"bracketSameLine": false, | ||
"embeddedLanguageFormatting": "auto", | ||
"htmlWhitespaceSensitivity": "css", | ||
"vueIndentScriptAndStyle": true, | ||
"quoteProps": "consistent", | ||
"proseWrap": "preserve", | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"useTabs": false, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,37 @@ | ||
# 👷 `worker-apollo-server-template` Quick start | ||
|
||
A template for kick starting a Cloudflare worker project to deploy Apollo Server v4 to Cloudflare Workers. | ||
A template for kick starting a Cloudflare Workers project to deploy Apollo Server v4. | ||
|
||
[`index.ts`](blob/main/src/index.ts) is the content of the Workers script. | ||
|
||
- [`handlers/apollo.ts`](blob/main/src/handlers/apollo.ts): Route handler for GraphQL query request | ||
- Cloudflare Workers - ESModule syntax + TypeScript | ||
- [@as-integrations/cloudflare-workers](https://www.npmjs.com/package/@as-integrations/cloudflare-workers) | ||
- Enable Playground / Sandbox by adding `plugins` + `introspection`: | ||
|
||
```javascript | ||
const server = new ApolloServer<ContextValue>({ | ||
typeDefs, | ||
resolvers, | ||
introspection: true, | ||
plugins: [ | ||
ApolloServerPluginLandingPageLocalDefault({ footer: false }), | ||
// ApolloServerPluginLandingPageProductionDefault({ | ||
// graphRef: 'my-graph-id@my-graph-variant', | ||
// footer: false, | ||
// }) | ||
], | ||
}); | ||
``` | ||
- [@apollo/datasource-rest](https://www.npmjs.com/package/@apollo/datasource-rest) integrated | ||
- [GraphQL Codegen](https://the-guild.dev/graphql/codegen) integrated | ||
|
||
## Example | ||
Live demo: https://worker-apollo-server.ds101.workers.dev | ||
|
||
Live: https://worker-apollo-server.ds101.workers.dev | ||
|
||
```graphql | ||
query { | ||
example | ||
pokemon(id: 1) { | ||
id | ||
name | ||
} | ||
} | ||
``` | ||
## Usage | ||
|
||
Response: | ||
- Click on the button `Use this template` | ||
- Install npm dependencies | ||
|
||
```json | ||
{ | ||
"data": { | ||
"example": "Hello world!", | ||
"pokemon": { | ||
"id": "1", | ||
"name": "bulbasaur" | ||
} | ||
} | ||
} | ||
```bash | ||
npm install | ||
``` | ||
|
||
## Development | ||
|
||
Click [Use this template](https://github.com/kimyvgy/worker-apollo-server/generate) button to create your own repository. | ||
|
||
Start your dev server with following commands: | ||
- Start app in the dev mode | ||
|
||
```sh | ||
yarn install | ||
yarn dev | ||
```bash | ||
npm run dev | ||
``` | ||
|
||
Open up [http://0.0.0.0:8787](http://0.0.0.0:8787) and you should be ready to go! | ||
|
||
> This template uses `graphql-codegen` to auto-generate Typescript types from `schema.graphql`. The types are generated to file `src/@types/schema.generated.ts`. So you can import Resolver Types from there. | ||
- If you edit the `src/schema.ts`, you must re-generate the schema type definitions: | ||
|
||
## Deployment | ||
|
||
If you don't already have an account, then [create a cloudflare account here](https://dash.cloudflare.com/sign-up) and after verifying your email address with Cloudflare, go to your dashboard and set up your free custom Cloudflare Workers subdomain. | ||
|
||
Please change the environment variables for Cloudflare Workers in `wrangler.toml` file: | ||
```toml | ||
# Example | ||
[env.production] | ||
name = "worker-apollo-server" | ||
[[env.production.kv_namespaces]] | ||
binding = "GRAPHQL_CACHE" | ||
id = "ba46c41d96544abba4aae3600c4955eb" | ||
[env.production.vars] | ||
GRAPHQL_BASE_ENDPOINT = "/" | ||
GRAPHQL_KV_CACHE = "true" | ||
```bash | ||
npm run generate | ||
``` | ||
|
||
Once that's done, you should be able to deploy your app: | ||
|
||
```sh | ||
yarn deploy --env production | ||
``` | ||
- Run tests: | ||
|
||
```bash | ||
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.ds101.workers.dev | ||
Done in 7.29s. | ||
npm run test | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { CodegenConfig } from '@graphql-codegen/cli'; | ||
import schema from './src/schema'; | ||
|
||
const config: CodegenConfig = { | ||
schema, | ||
generates: { | ||
'src/@types/apollo-server.d.ts': { | ||
plugins: ['typescript', 'typescript-resolvers'], | ||
config: { | ||
enumsAsConst: true, | ||
namingConvention: { | ||
enumValues: "keep" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default config; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
{ | ||
"name": "worker-apollo-server", | ||
"main": "./build/index.js", | ||
"name": "template-worker-typescript", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"generate": "graphql-codegen --config codegen.yml", | ||
"build": "NODE_ENV=production node worker.build.js", | ||
"dev": "miniflare --watch --debug --host 0.0.0.0 --kv GRAPHQL_CACHE", | ||
"deploy": "wrangler publish", | ||
"deploy-prod": "wrangler publish --env production" | ||
"deploy": "wrangler deploy src/index.ts", | ||
"dev": "wrangler dev", | ||
"start": "wrangler dev", | ||
"test": "vitest run", | ||
"generate": "graphql-codegen" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20221111.1", | ||
"@esbuild-plugins/node-globals-polyfill": "^0.2.0", | ||
"@esbuild-plugins/node-modules-polyfill": "^0.2.0", | ||
"@graphql-codegen/cli": "^5.0.0", | ||
"@graphql-codegen/typescript": "^4.0.0", | ||
"@graphql-codegen/typescript-resolvers": "^4.0.0", | ||
"@graphql-tools/optimize": "^2.0.0", | ||
"@luckycatfactory/esbuild-graphql-loader": "^3.7.0", | ||
"esbuild": "^0.20.0", | ||
"miniflare": "3.20240320.1", | ||
"typescript": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
"@cloudflare/workers-types": "^4.20231016.0", | ||
"@graphql-codegen/cli": "^5.0.2", | ||
"@graphql-codegen/typescript": "^4.0.6", | ||
"@graphql-codegen/typescript-resolvers": "^4.0.6", | ||
"typescript": "^5.0.4", | ||
"vitest": "^1.4.0", | ||
"wrangler": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"@apollo/datasource-rest": "^6.0.0", | ||
"@apollo/server": "^4.3.0", | ||
"@as-integrations/cloudflare-workers": "^0.2.0", | ||
"graphql": "^16.6.0" | ||
"@apollo/datasource-rest": "^6.2.2", | ||
"@apollo/server": "^4.10.2", | ||
"@as-integrations/cloudflare-workers": "^1.0.0-alpha", | ||
"graphql": "^16.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,5 @@ | |
} | ||
], | ||
"automergeType": "branch", | ||
"platformAutomerge": true, | ||
"ignoreTests": true | ||
"platformAutomerge": true | ||
} |
Oops, something went wrong.