Skip to content

Commit 24f2a9b

Browse files
authored
chore(node): update examples for different runtimes (#54)
1 parent e4796ff commit 24f2a9b

11 files changed

Lines changed: 423 additions & 14 deletions

File tree

README.md

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,80 @@ Effortlessly craft GraphQL APIs on the Edge, designed to thrive across various J
44

55
| Runtime | Status | Example |
66
| ------------- | ------------- | ------------- |
7-
| Cloudflare Worker | :white_check_mark: | [cloudflare](examples/cloudflare) |
8-
| Bun | :white_check_mark: | [Bun](examples/bun) |
9-
| Deno | :white_large_square: Pending | |
10-
| Vercel | :white_large_square: Pending | |
11-
| Node | :white_large_square: Pending | |
7+
| Cloudflare Workers | :white_check_mark: | [cloudflare](examples/cloudflare) |
8+
| Node | :white_check_mark: | [node](examples/node) |
9+
| Bun | :white_check_mark: | [Bun](examples/bun) |
10+
| Deno | :white_large_square: Pending | |
11+
| Vercel | :white_large_square: Pending | |
1212

13-
## Quick Start
13+
## EdgeQL on JavaScript Runtimes
14+
15+
### Node
16+
17+
```javascript
18+
import { NodeEdgeQL } from 'edgeql/node'
19+
20+
const app = new NodeEdgeQL()
21+
22+
app.handle(`
23+
type Query {
24+
hello: String
25+
}
26+
`, (ctx) => {
27+
return `hello from EdgeQL on ${ctx.runtime.runtime}`
28+
})
29+
30+
app.listen({port: 4000}, ({address, family, port}) => {
31+
console.log(address, family, port)
32+
})
33+
```
34+
35+
### Bun
36+
37+
```typescript
38+
import { EdgeQL } from 'edgeql'
39+
import type { Context } from 'edgeql'
40+
41+
const app = new EdgeQL()
42+
43+
app.handle(`
44+
type Query {
45+
hello: String
46+
}
47+
`, (_ctx: Context) => {
48+
return 'hello from EdgeQL on Bun'
49+
})
50+
51+
const port = Bun.env['PORT'] ? parseInt(Bun.env['PORT']) : 3000
52+
console.log(`Running at http://localhost:${port}`)
53+
54+
export default {
55+
port,
56+
fetch: app.fetch
57+
}
58+
```
59+
60+
### Cloudflare Workers
61+
62+
```typescript
63+
import { EdgeQL } from 'edgeql'
64+
import type { Context } from 'edgeql'
65+
66+
const app = new EdgeQL()
67+
68+
app.handle(
69+
`
70+
type Query {
71+
whereami: String
72+
}
73+
`,
74+
(ctx: Context) => {
75+
return `EdgeQL is running on ${ctx.runtime.runtime}`
76+
})
77+
```
78+
79+
80+
## Schema Design Approaches
1481

1582
EdgeQL supports both Schema-First and Code-First.
1683

examples/bun/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"module": "app.ts",
44
"type": "module",
55
"devDependencies": {
6-
"@types/bun": "^1.0.8",
7-
"edgeql": "^0.1.3"
6+
"edgeql": "^0.1.9",
7+
"@types/bun": "^1.0.8"
88
},
99
"peerDependencies": {
1010
"typescript": "^5.0.0"
1111
}
12-
}
12+
}

examples/bun/yarn.lock

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@graphql-tools/merge@^9.0.3":
6+
version "9.0.3"
7+
resolved "https://registry.yarnpkg.com/@graphql-tools/merge/-/merge-9.0.3.tgz#4d0b467132e6f788b69fab803d31480b8ce4b61a"
8+
integrity sha512-FeKv9lKLMwqDu0pQjPpF59GY3HReUkWXKsMIuMuJQOKh9BETu7zPEFUELvcw8w+lwZkl4ileJsHXC9+AnsT2Lw==
9+
dependencies:
10+
"@graphql-tools/utils" "^10.0.13"
11+
tslib "^2.4.0"
12+
13+
"@graphql-tools/schema@^10.0.2":
14+
version "10.0.3"
15+
resolved "https://registry.yarnpkg.com/@graphql-tools/schema/-/schema-10.0.3.tgz#48c14be84cc617c19c4c929258672b6ab01768de"
16+
integrity sha512-p28Oh9EcOna6i0yLaCFOnkcBDQECVf3SCexT6ktb86QNj9idnkhI+tCxnwZDh58Qvjd2nURdkbevvoZkvxzCog==
17+
dependencies:
18+
"@graphql-tools/merge" "^9.0.3"
19+
"@graphql-tools/utils" "^10.0.13"
20+
tslib "^2.4.0"
21+
value-or-promise "^1.0.12"
22+
23+
"@graphql-tools/utils@^10.0.13":
24+
version "10.1.2"
25+
resolved "https://registry.yarnpkg.com/@graphql-tools/utils/-/utils-10.1.2.tgz#192de00e7301c0242e7305ab16bbeef76bbcec74"
26+
integrity sha512-fX13CYsDnX4yifIyNdiN0cVygz/muvkreWWem6BBw130+ODbRRgfiVveL0NizCEnKXkpvdeTy9Bxvo9LIKlhrw==
27+
dependencies:
28+
"@graphql-typed-document-node/core" "^3.1.1"
29+
cross-inspect "1.0.0"
30+
dset "^3.1.2"
31+
tslib "^2.4.0"
32+
33+
"@graphql-typed-document-node/core@^3.1.1":
34+
version "3.2.0"
35+
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861"
36+
integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==
37+
38+
"@hono/node-server@^1.8.2":
39+
version "1.8.2"
40+
resolved "https://registry.yarnpkg.com/@hono/node-server/-/node-server-1.8.2.tgz#940b3a0dbd7adbc510b79b626f3603258493354b"
41+
integrity sha512-h8l2TBLCPHZBUrrkosZ6L5CpBLj6zdESyF4B+zngiCDF7aZFQJ0alVbLx7jn8PCVi9EyoFf8a4hOZFi1tD95EA==
42+
43+
"@types/bun@^1.0.8":
44+
version "1.0.8"
45+
resolved "https://registry.yarnpkg.com/@types/bun/-/bun-1.0.8.tgz#5228b0c5c84150f8fe85d4eac851bca2d6250526"
46+
integrity sha512-E6UWZuN4ymAxzUBWVIGDHJ3Zey7I8cMzDZ+cB1BqhZsmd1uPb9iAQzpWMruY1mKzsuD3R+dZPoBkZz8QL1KhSA==
47+
dependencies:
48+
bun-types "1.0.29"
49+
50+
"@types/node@*", "@types/node@~20.11.3":
51+
version "20.11.27"
52+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.27.tgz#debe5cfc8a507dd60fe2a3b4875b1604f215c2ac"
53+
integrity sha512-qyUZfMnCg1KEz57r7pzFtSGt49f6RPkPBis3Vo4PbS7roQEDn22hiHzl/Lo1q4i4hDEgBJmBF/NTNg2XR0HbFg==
54+
dependencies:
55+
undici-types "~5.26.4"
56+
57+
"@types/ws@~8.5.10":
58+
version "8.5.10"
59+
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787"
60+
integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==
61+
dependencies:
62+
"@types/node" "*"
63+
64+
bun-types@1.0.29:
65+
version "1.0.29"
66+
resolved "https://registry.yarnpkg.com/bun-types/-/bun-types-1.0.29.tgz#b761f9c181aa0efa1c749ddfba2a28e4778dfaf2"
67+
integrity sha512-Z+U1ORr/2UCwxelIZxE83pyPLclviYL9UewQCNEUmGeLObY8ao+3WF3D8N1+NMv2+S+hUWsdBJam+4GoPEz35g==
68+
dependencies:
69+
"@types/node" "~20.11.3"
70+
"@types/ws" "~8.5.10"
71+
72+
cross-inspect@1.0.0:
73+
version "1.0.0"
74+
resolved "https://registry.yarnpkg.com/cross-inspect/-/cross-inspect-1.0.0.tgz#5fda1af759a148594d2d58394a9e21364f6849af"
75+
integrity sha512-4PFfn4b5ZN6FMNGSZlyb7wUhuN8wvj8t/VQHZdM4JsDcruGJ8L2kf9zao98QIrBPFCpdk27qst/AGTl7pL3ypQ==
76+
dependencies:
77+
tslib "^2.4.0"
78+
79+
dset@^3.1.2:
80+
version "3.1.3"
81+
resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.3.tgz#c194147f159841148e8e34ca41f638556d9542d2"
82+
integrity sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==
83+
84+
edgeql@^0.1.9:
85+
version "0.1.9"
86+
resolved "https://registry.yarnpkg.com/edgeql/-/edgeql-0.1.9.tgz#a94ed2cbf9555ee0bc2ffdfa86c5edff10ffbf7c"
87+
integrity sha512-OO9RWmar+owXW8YxuAij6XuGLVGQsK/cO5N6/BXduUejErrG9LdqckpXY8DJ8AjZmMBB+m4AQkz9ZgYGR8eREg==
88+
dependencies:
89+
"@graphql-tools/schema" "^10.0.2"
90+
"@hono/node-server" "^1.8.2"
91+
graphql "^16.8.1"
92+
93+
graphql@^16.8.1:
94+
version "16.8.1"
95+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07"
96+
integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==
97+
98+
tslib@^2.4.0:
99+
version "2.6.2"
100+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
101+
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
102+
103+
undici-types@~5.26.4:
104+
version "5.26.5"
105+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
106+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
107+
108+
value-or-promise@^1.0.12:
109+
version "1.0.12"
110+
resolved "https://registry.yarnpkg.com/value-or-promise/-/value-or-promise-1.0.12.tgz#0e5abfeec70148c78460a849f6b003ea7986f15c"
111+
integrity sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q==

examples/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"wrangler": "^3.0.0"
1414
},
1515
"dependencies": {
16-
"edgeql": "^0.1.3",
16+
"edgeql": "^0.1.9",
1717
"graphql": "^16.8.1"
1818
}
1919
}

examples/cloudflare/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const clock: GraphQLSchema = new GraphQLSchema({
3636
})
3737
})
3838

39+
app.handle(
40+
`
41+
type Query {
42+
whereami: String
43+
}
44+
`,
45+
(ctx: Context) => {
46+
return `EdgeQL is running on ${ctx.runtime.runtime}`
47+
})
48+
3949
app.handle(helloworld)
4050
app.handle(clock)
4151

examples/cloudflare/yarn.lock

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@
207207
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861"
208208
integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==
209209

210+
"@hono/node-server@^1.8.2":
211+
version "1.8.2"
212+
resolved "https://registry.yarnpkg.com/@hono/node-server/-/node-server-1.8.2.tgz#940b3a0dbd7adbc510b79b626f3603258493354b"
213+
integrity sha512-h8l2TBLCPHZBUrrkosZ6L5CpBLj6zdESyF4B+zngiCDF7aZFQJ0alVbLx7jn8PCVi9EyoFf8a4hOZFi1tD95EA==
214+
210215
"@jridgewell/resolve-uri@^3.0.3":
211216
version "3.1.1"
212217
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721"
@@ -333,12 +338,13 @@ dset@^3.1.2:
333338
resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.3.tgz#c194147f159841148e8e34ca41f638556d9542d2"
334339
integrity sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==
335340

336-
edgeql@^0.1.3:
337-
version "0.1.3"
338-
resolved "https://registry.yarnpkg.com/edgeql/-/edgeql-0.1.3.tgz#54eb2bbc547c7271019b47eb77a2ec43b091fc82"
339-
integrity sha512-NbZOTQhZvTd5LFXTgPVN9GBIqLy38VSSM9fM/VecsiQHjdsI5NT4a0nF3WBbWevnhJ4ihIS8BE9pVwAYQL6Jsg==
341+
edgeql@^0.1.9:
342+
version "0.1.9"
343+
resolved "https://registry.yarnpkg.com/edgeql/-/edgeql-0.1.9.tgz#a94ed2cbf9555ee0bc2ffdfa86c5edff10ffbf7c"
344+
integrity sha512-OO9RWmar+owXW8YxuAij6XuGLVGQsK/cO5N6/BXduUejErrG9LdqckpXY8DJ8AjZmMBB+m4AQkz9ZgYGR8eREg==
340345
dependencies:
341346
"@graphql-tools/schema" "^10.0.2"
347+
"@hono/node-server" "^1.8.2"
342348
graphql "^16.8.1"
343349

344350
esbuild@0.17.19:

examples/node/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# edgeql-on-node-example
2+
3+
EdgeQL works on Node out of box.
4+
5+
### JavaScript
6+
7+
```javascript
8+
import { NodeEdgeQL } from 'edgeql/node'
9+
10+
const app = new NodeEdgeQL()
11+
12+
app.handle(`
13+
type Query {
14+
hello: String
15+
}
16+
`, (ctx) => {
17+
return `hello from EdgeQL on ${ctx.runtime.runtime}`
18+
})
19+
20+
app.listen({port: 4000}, ({address, family, port}) => {
21+
console.log(address, family, port)
22+
})
23+
```
24+
25+
### TypeScript
26+
27+
```typescript
28+
import type { Context } from 'edgeql'
29+
import { NodeEdgeQL } from 'edgeql/node'
30+
31+
const app = new NodeEdgeQL()
32+
33+
app.handle(`
34+
type Query {
35+
hello: String
36+
}
37+
`, (ctx: Context) => {
38+
return `hello from EdgeQL on ${ctx.runtime.runtime}`
39+
})
40+
41+
app.listen({port: 4000}, ({address, family, port}) => {
42+
console.log(address, family, port)
43+
})
44+
```

examples/node/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "edgeql-on-node-example",
3+
"main": "dist/app.js",
4+
"module": "app.ts",
5+
"type": "module",
6+
"scripts": {
7+
"build": "tsc -p tsconfig.json",
8+
"prestart": "yarn build",
9+
"start": "node dist/app.js"
10+
},
11+
"devDependencies": {},
12+
"peerDependencies": {
13+
"typescript": "^5.4.0"
14+
},
15+
"dependencies": {
16+
"@hono/node-server": "^1.8.2",
17+
"@types/node": "^20.11.27",
18+
"edgeql": "^0.1.9",
19+
"typescript": "^5.4.2"
20+
},
21+
"engines": {
22+
"node": ">=18.0.0"
23+
}
24+
}

examples/node/src/app.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Context } from 'edgeql'
2+
import { NodeEdgeQL } from 'edgeql/node'
3+
4+
const app = new NodeEdgeQL()
5+
6+
app.handle(`
7+
type Query {
8+
hello: String
9+
}
10+
`, (ctx: Context) => {
11+
return `hello from EdgeQL on ${ctx.runtime.runtime}`
12+
})
13+
14+
app.listen({port: 4000}, ({address, family, port}) => {
15+
console.log(address, family, port)
16+
})

examples/node/tsconfig.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"ESNext",
5+
"DOM"
6+
],
7+
"target": "ESNext",
8+
"module": "ESNext",
9+
"moduleDetection": "force",
10+
"jsx": "react-jsx",
11+
"allowJs": true,
12+
13+
"outDir": "dist/",
14+
15+
"types": [
16+
"jest",
17+
"node"
18+
],
19+
20+
"moduleResolution": "bundler",
21+
"verbatimModuleSyntax": true,
22+
"noEmit": false,
23+
24+
"strict": true,
25+
"skipLibCheck": true,
26+
"noFallthroughCasesInSwitch": true,
27+
28+
"noUnusedLocals": true,
29+
"noUnusedParameters": true,
30+
"noPropertyAccessFromIndexSignature": true
31+
},
32+
"include": ["src/**/*.ts"],
33+
"exclude": [
34+
"node_modules",
35+
"dist"
36+
]
37+
}

0 commit comments

Comments
 (0)