Skip to content

Commit

Permalink
Move Schema Stitching (#118)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: enisdenjo <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent bb5a756 commit 73c621d
Show file tree
Hide file tree
Showing 309 changed files with 64,191 additions and 203 deletions.
7 changes: 7 additions & 0 deletions .changeset/@graphql-hive_gateway-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-hive/gateway': patch
---

dependencies updates:

- Updated dependency [`@graphql-mesh/plugin-jit@^0.0.7` ↗︎](https://www.npmjs.com/package/@graphql-mesh/plugin-jit/v/0.0.7) (from `^0.0.6`, in `dependencies`)
12 changes: 12 additions & 0 deletions .changeset/@graphql-hive_gateway-runtime-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@graphql-hive/gateway-runtime': patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/batch-delegate@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/batch-delegate/v/workspace:^) (from `^9.0.13`, in `dependencies`)
- Updated dependency [`@graphql-tools/delegate@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/workspace:^) (from `^10.1.1`, in `dependencies`)
- Updated dependency [`@graphql-tools/executor-http@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/executor-http/v/workspace:^) (from `^1.1.5`, in `dependencies`)
- Updated dependency [`@graphql-tools/federation@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/federation/v/workspace:^) (from `^2.2.25`, in `dependencies`)
- Updated dependency [`@graphql-tools/stitch@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitch/v/workspace:^) (from `^9.3.3`, in `dependencies`)
- Updated dependency [`@graphql-tools/wrap@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/workspace:^) (from `^10.0.15`, in `dependencies`)
11 changes: 11 additions & 0 deletions .changeset/@graphql-mesh_fusion-runtime-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@graphql-mesh/fusion-runtime': patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/delegate@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/workspace:^) (from `^10.0.28`, in `dependencies`)
- Updated dependency [`@graphql-tools/federation@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/federation/v/workspace:^) (from `^2.2.21`, in `dependencies`)
- Updated dependency [`@graphql-tools/stitch@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitch/v/workspace:^) (from `^9.2.17`, in `dependencies`)
- Updated dependency [`@graphql-tools/stitching-directives@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitching-directives/v/workspace:^) (from `^3.1.9`, in `dependencies`)
- Updated dependency [`@graphql-tools/wrap@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/workspace:^) (from `^10.0.12`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_transport-common-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-mesh/transport-common': patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/delegate@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/workspace:^) (from `^10.0.28`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_transport-http-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-mesh/transport-http': patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/executor-http@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/executor-http/v/workspace:^) (from `^1.1.8`, in `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_transport-ws-118-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-mesh/transport-ws': patch
---

dependencies updates:

- Updated dependency [`@graphql-tools/executor-graphql-ws@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-tools/executor-graphql-ws/v/workspace:^) (from `^1.3.0`, in `dependencies`)
59 changes: 59 additions & 0 deletions .changeset/ninety-grapes-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
'@graphql-tools/delegate': patch
---

Do not ignore request selection set when overriding the fields

```ts
import { buildSchema, graphql } from 'graphql';
import { addResolversToSchema } from '@graphql-tools/schema';
import { stitchSchemas } from '@graphql-tools/stitch';
import { delegateToSchema } from '@graphql-tools/delegate';

const sub_schema = addResolversToSchema({
schema: buildSchema(`
type Query {
current_user: User
}
type User {
id: ID!
name: String!
age: Int!
}
`),
resolvers: {
Query: {
current_user: () => ({ id: '5', name: 'John Doe', age: 10 }),
},
},
});

const stitched_schema = stitchSchemas({
subschemas: [
{
schema: sub_schema,
createProxyingResolver: (options) => {
return (_parent, _args, context, info) => {
const operationName = info.operation.name ? info.operation.name.value : undefined;
return delegateToSchema({
schema: options.subschemaConfig,
operation: options.operation,
context,
info,
operationName,
});
};
},
},
],
resolvers: {
User: {
name: {
selectionSet: '{ age }',
resolve: (parent) => `${parent.name}(${parent.age})`, // Age should be here
},
},
},
});
```
31 changes: 31 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Bench
on:
push:
branches:
- main
pull_request:

jobs:
bench:
strategy:
fail-fast: false
matrix:
products_size:
- 3
- 10
- 50
- 100
- 1000
name: Federation Benchmark with ${{matrix.products_size}} Products
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up env
uses: the-guild-org/shared-config/setup@v1
with:
node-version: 22
- name: Bench
run: yarn bench
env:
PRODUCTS_SIZE: ${{matrix.products_size}}
2 changes: 0 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
branches:
- main
pull_request:
branches:
- main

jobs:
format:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- main
pull_request:
branches:
- main

jobs:
unit:
Expand Down Expand Up @@ -36,7 +34,6 @@ jobs:
matrix:
node-version:
- 18
- 22
name: Leaks / Node v${{matrix.node-version}}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -108,8 +105,8 @@ jobs:
continue-on-error: true
with:
key: docker-images-${{ runner.os }}-${{ steps.hash-docker-images.outputs.result }}
- if: matrix.setup.gateway-runner == 'docker'
name: Build # TODO: necessary only because we're in a mid-state with moving packages from graphql-mesh. this step wont be necessary once all gateway components have been moved
- if: matrix.setup.gateway-runner == 'docker' || matrix.setup.gateway-runner == 'bin'
name: Build # TODO: necessary only because rollup does not use tsconfig paths within node_modules and we have packages scattered between Mesh and Hive GW repos
run: yarn build
- if: matrix.setup.gateway-runner == 'docker' || matrix.setup.gateway-runner == 'bin'
name: Bundle
Expand Down
48 changes: 48 additions & 0 deletions .yarn/patches/vite-tsconfig-paths-npm-5.1.2-40407aa097.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/dist/index.js b/dist/index.js
index 272aa3b7abc2f889e8feddd1ae4b11f81594472d..16fdcc182f32d04809440d2ec390e7e146888711 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -48,6 +48,7 @@ var debug = _debug("vite-tsconfig-paths");
var noMatch = [void 0, false];
var src_default = (opts = {}) => {
let resolversByDir;
+ let inlinedModules;
return {
name: "vite-tsconfig-paths",
enforce: "pre",
@@ -60,9 +61,11 @@ var src_default = (opts = {}) => {
} else {
workspaceRoot = searchForWorkspaceRoot(projectRoot);
}
+ inlinedModules = config.test?.server?.deps?.inline || [];
debug("options.root ==", root);
debug("project root ==", projectRoot);
debug("workspace root ==", workspaceRoot);
+ debug("inlined modules ==", inlinedModules);
if (root) {
projectRoot = root;
workspaceRoot = root;
@@ -257,12 +260,17 @@ var src_default = (opts = {}) => {
}
importer = normalizePath2(importer);
const importerFile = importer.replace(/[#?].+$/, "");
- if (!importerExtRE.test(importerFile)) {
- return noMatch;
- }
- const relativeImporterFile = relative(configDir, importerFile);
- if (!isIncludedRelative(relativeImporterFile)) {
- return noMatch;
+ const inlined = inlinedModules.some((m) => m.test(importerFile));
+ if (inlined) {
+ debug(`module inlined:`, importer);
+ } else {
+ if (!importerExtRE.test(importerFile)) {
+ return noMatch;
+ }
+ const relativeImporterFile = relative(configDir, importerFile);
+ if (!isIncludedRelative(relativeImporterFile)) {
+ return noMatch;
+ }
}
const suffix = (_a2 = /\?.+$/.exec(id)) == null ? void 0 : _a2[0];
if (suffix) {
Empty file modified .yarn/releases/yarn-4.5.1.cjs
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ yarnPath: .yarn/releases/yarn-4.5.1.cjs # TODO: corepack does not work in github
nodeLinker: node-modules
npmPublishRegistry: https://registry.npmjs.org
npmAuthToken: ${NPM_TOKEN:-}
checksumBehavior: ignore
4 changes: 4 additions & 0 deletions DEPS_RESOLUTIONS_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ Here we collect reasons and write explanations about why some resolutions or pat
### tsx

1. https://github.com/privatenumber/tsx/issues/159#issuecomment-2473632866 (did what was suggested)

### vitest-tsconfig-paths

1. Resolve tsconfig paths in modules that have been [inlined](https://vitest.dev/config/#server-deps-inline).
23 changes: 23 additions & 0 deletions bench/federation/apollo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ApolloGateway, LocalGraphQLDataSource } from '@apollo/gateway';
import * as accounts from './services/accounts';
import * as inventory from './services/inventory';
import * as products from './services/products';
import * as reviews from './services/reviews';

const serviceMap = {
accounts,
inventory,
products,
reviews,
};

export default new ApolloGateway({
localServiceList: Object.entries(serviceMap).map(([name, { typeDefs }]) => ({
name,
typeDefs,
})),
buildService: ({ name }) => {
const serviceName = name as keyof typeof serviceMap;
return new LocalGraphQLDataSource(serviceMap[serviceName].schema);
},
});
Loading

0 comments on commit 73c621d

Please sign in to comment.