Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify server handling and improve CF Workers compatibility #4440

Merged
merged 3 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/@graphql-mesh_cli-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@graphql-mesh/cli": patch
---

dependencies updates:

- Added dependency [`@graphql-mesh/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-mesh/http/v/0.0.0) (to `dependencies`)
- Added dependency [`@whatwg-node/[email protected]` ↗︎](https://www.npmjs.com/package/@whatwg-node/server/v/0.1.2) (to `dependencies`)
- Added dependency [`@whatwg-node/[email protected]` ↗︎](https://www.npmjs.com/package/@whatwg-node/fetch/v/0.3.2) (to `dependencies`)
- Added dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-yoga/v/3.0.0-alpha-20220905163021-e923bb34) (to `dependencies`)
- Added dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/itty-router/v/2.6.1) (to `dependencies`)
- Added dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/itty-router-extras/v/0.4.2) (to `dependencies`)
- Removed dependency [`@graphql-yoga/node@^2.4.0` ↗︎](https://www.npmjs.com/package/@graphql-yoga/node/v/null) (from `dependencies`)
- Removed dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/cookie-parser/v/1.4.6) (from `dependencies`)
- Removed dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/cors/v/2.8.5) (from `dependencies`)
- Removed dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/express/v/4.18.1) (from `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_graphql-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/graphql": patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/url-loader/v/7.15.0) (from `7.14.2`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_grpc-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/grpc": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_json-schema-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/json-schema": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_mongoose-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/mongoose": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_mysql-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/mysql": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_odata-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/odata": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@omnigraph_json-schema-4440-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@omnigraph/json-schema": patch
---

dependencies updates:

- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/graphql-compose/v/9.0.9) (from `9.0.8`, in `dependencies`)
15 changes: 15 additions & 0 deletions .changeset/afraid-pumpkins-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@graphql-mesh/cli': minor
'@graphql-mesh/http': minor
---

- Drop express and other Node specific server packages
- Introduce a new platform agnostic HTTP handler package using itty-router and @whatwg-node/server
- Introduce a new function in the artifacts that allows you to create a platform agnostic HTTP handler;

For example in CF Workers
```ts
import { createBuiltMeshHTTPHandler } from '../.mesh';

self.addEventListener('fetch', createBuiltMeshHTTPHandler());
```
5 changes: 5 additions & 0 deletions .changeset/great-lobsters-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/graphql': patch
---

Bump url loader to fix `credentials` error in CF Workers
11 changes: 11 additions & 0 deletions .changeset/hungry-kiwis-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@graphql-mesh/grpc': patch
'@graphql-mesh/json-schema': patch
'@graphql-mesh/mongoose': patch
'@graphql-mesh/mysql': patch
'@graphql-mesh/odata': patch
'@omnigraph/json-schema': patch
'@graphql-mesh/types': patch
---

Bump graphql-compose to fix incompatibility issues with non Node.js environments
25 changes: 2 additions & 23 deletions examples/cloudflare-workers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
import { getBuiltMesh } from '../.mesh';
import { createServer } from '@graphql-yoga/common';
import { createBuiltMeshHTTPHandler } from '../.mesh';

async function handleRequest(request: Request, event: any) {
try {
const mesh = await getBuiltMesh();
const server = createServer({
plugins: mesh.plugins,
maskedErrors: false,
graphiql: {
title: 'OpenBrewery Mesh',
},
});
return server.handleRequest(request, event);
} catch (e) {
return new Response(e.stack, {
status: 500,
});
}
}

self.addEventListener('fetch', (event: any) => {
event.respondWith(handleRequest(event.request, event));
});
self.addEventListener('fetch', createBuiltMeshHTTPHandler());
5 changes: 2 additions & 3 deletions examples/cloudflare-workers/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name = "breweries_mesh"
main = "src/index.ts"
compatibility_date = "2022-06-27"
# TODO: remove this when graphql-compose doesn't have the following import
# https://github.com/graphql-compose/graphql-compose/blob/master/src/Resolver.ts#L3
node_compat = true
account_id = "47efd9199a2f2a26049d85b9d3dfe31a"
kv_namespaces = [
{ binding = "MESH", id = "6efcacf054f9427e8b5f70b28da08e07", preview_id = "0418af2eda0646928a23850d278837e5" }
Expand All @@ -13,3 +10,5 @@ usage_model = "bundled"
[vars]
DEBUG = "1"

[build]
command = "mesh build"
2 changes: 0 additions & 2 deletions examples/spacex-cfw/.meshrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ sources:
# Use some fetch strategy
timeout: 2000
retry: 2
# The following is needed for Cloudflare Workers
credentials: disable

plugins:
- responseCache:
Expand Down
25 changes: 2 additions & 23 deletions examples/spacex-cfw/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
import { getBuiltMesh } from '../.mesh';
import { createServer } from '@graphql-yoga/common';
import { createBuiltMeshHTTPHandler } from '../.mesh';

async function handleRequest(request: Request, event: any) {
try {
const mesh = await getBuiltMesh();
const server = createServer({
plugins: mesh.plugins,
maskedErrors: false,
graphiql: {
title: 'SpaceX Mesh',
},
});
return server.handleRequest(request, event);
} catch (e) {
return new Response(e.stack, {
status: 500,
});
}
}

self.addEventListener('fetch', (event: any) => {
event.respondWith(handleRequest(event.request, event));
});
self.addEventListener('fetch', createBuiltMeshHTTPHandler());
3 changes: 3 additions & 0 deletions examples/spacex-cfw/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ kv_namespaces = [
[vars]
DEBUG = "1"
GRAPHQL_API = "https://api.spacex.land/graphql/"

[build]
command = "mesh build"
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@
"@graphql-mesh/utils": "0.41.2",
"@graphql-mesh/store": "0.8.35",
"@graphql-mesh/types": "0.82.1",
"@graphql-mesh/http": "0.0.0",
"@graphql-tools/code-file-loader": "7.3.4",
"@graphql-tools/utils": "8.10.1",
"@graphql-tools/load": "7.7.5",
"@graphql-tools/graphql-file-loader": "7.5.3",
"@graphql-tools/wrap": "9.0.5",
"@graphql-yoga/node": "^2.4.0",
"cookie-parser": "1.4.6",
"cors": "2.8.5",
"@whatwg-node/server": "0.1.2",
"@whatwg-node/fetch": "0.3.2",
"graphql-yoga": "3.0.0-alpha-20220905163021-e923bb34",
"itty-router": "2.6.1",
"itty-router-extras": "0.4.2",
"dotenv": "16.0.2",
"dnscache": "1.0.2",
"graphql-import-node": "0.0.5",
"express": "4.18.1",
"graphql-ws": "5.10.1",
"change-case": "4.1.2",
"json-bigint-patch": "0.0.8",
Expand All @@ -82,9 +84,7 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@types/cors": "2.8.12",
"@types/cookie-parser": "1.4.3",
"@types/express": "4.17.13",
"@types/itty-router-extras": "0.4.0",
"@types/mkdirp": "1.0.2",
"@types/yargs": "17.0.12",
"@types/ws": "8.5.3",
Expand Down
63 changes: 0 additions & 63 deletions packages/cli/src/commands/serve/graphql-handler.ts

This file was deleted.

Loading