Skip to content

Commit 18e0d49

Browse files
committed
feat(runtime): add DISABLE_JIT flag to disable GraphQL JIT
1 parent e67f9f3 commit 18e0d49

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

.changeset/old-moles-pump.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-mesh/runtime": patch
3+
---
4+
5+
Add DISABLE_JIT flag to disable GraphQL JIT

examples/federation-example/gateway-supergraph/.meshrc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ sources:
44
supergraph:
55
source: ./supergraph.graphql
66

7-
documents:
8-
- example-query.graphql
7+
# documents:
8+
# - example-query.graphql
99

1010
serve:
1111
playground: true

examples/federation-example/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
"start": "concurrently \"npm:start-services npm:start-gateway-delayed\"",
1212
"start-gateway": "mesh dev --dir gateway",
1313
"start-gateway-delayed": "delay 1 && npm run start-gateway",
14+
"start-gateway-supergraph": "mesh dev --dir gateway-supergraph",
15+
"start-gateway-supergraph-delayed": "delay 1 && npm run start-gateway-supergraph",
1416
"start-service-accounts": "ts-node services/accounts/index.ts",
1517
"start-service-accounts-subgraph": "ts-node services/accounts-subgraph/index.ts",
1618
"start-service-inventory": "ts-node services/inventory/index.ts",
1719
"start-service-products": "ts-node services/products/index.ts",
1820
"start-service-reviews": "ts-node services/reviews/index.ts",
1921
"start-services": "concurrently \"npm:start-service-*\"",
22+
"start-supergraph": "concurrently \"npm:start-services npm:start-gateway-supergraph-delayed\"",
2023
"test": "jest"
2124
},
2225
"devDependencies": {

examples/federation-example/services/inventory/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inspect } from 'node:util';
22
import { parse } from 'graphql';
3-
import { ApolloServer } from '@apollo/server/';
3+
import { ApolloServer } from '@apollo/server';
44
import { startStandaloneServer } from '@apollo/server/standalone';
55
import { buildSubgraphSchema } from '@apollo/subgraph';
66

examples/federation-example/services/products/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from 'graphql';
2-
import { ApolloServer } from '@apollo/server/';
2+
import { ApolloServer } from '@apollo/server';
33
import { startStandaloneServer } from '@apollo/server/standalone';
44
import { buildSubgraphSchema } from '@apollo/subgraph';
55

examples/federation-example/services/reviews/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from 'graphql';
2-
import { ApolloServer } from '@apollo/server/';
2+
import { ApolloServer } from '@apollo/server';
33
import { startStandaloneServer } from '@apollo/server/standalone';
44
import { buildSubgraphSchema } from '@apollo/subgraph';
55

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4+
"moduleResolution": "node",
45
"target": "es6",
56
"rootDir": "./",
67
"esModuleInterop": true
7-
}
8+
},
9+
"files": ["tests/federation-example.test.ts"]
810
}

packages/legacy/runtime/src/utils.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
import { ASTNode, BREAK, getNamedType, GraphQLSchema, visit } from 'graphql';
2+
import { getDocumentString } from '@envelop/core';
23
import { MapperKind, mapSchema, memoize1 } from '@graphql-tools/utils';
34

45
export const isStreamOperation = memoize1(function isStreamOperation(astNode: ASTNode): boolean {
6+
if (globalThis.process?.env?.DISABLE_JIT) {
7+
return true;
8+
}
9+
const documentStr = getDocumentString(astNode);
510
let isStream = false;
6-
visit(astNode, {
7-
Field: {
8-
enter(node): typeof BREAK {
9-
if (node.directives?.some(d => d.name.value === 'stream')) {
10-
isStream = true;
11-
return BREAK;
12-
}
13-
return undefined;
11+
if (documentStr.includes('@stream')) {
12+
visit(astNode, {
13+
Field: {
14+
enter(node): typeof BREAK {
15+
if (node.directives?.some(d => d.name.value === 'stream')) {
16+
isStream = true;
17+
return BREAK;
18+
}
19+
return undefined;
20+
},
1421
},
15-
},
16-
});
22+
});
23+
}
1724
return isStream;
1825
});
1926

2027
export const isGraphQLJitCompatible = memoize1(function isGraphQLJitCompatible(
2128
schema: GraphQLSchema,
2229
) {
30+
if (globalThis.process?.env?.DISABLE_JIT) {
31+
return false;
32+
}
2333
let compatibleSchema = true;
2434
mapSchema(schema, {
2535
[MapperKind.INPUT_OBJECT_TYPE]: type => {

0 commit comments

Comments
 (0)