Skip to content

Commit

Permalink
feat(runtime): add DISABLE_JIT flag to disable GraphQL JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Mar 18, 2024
1 parent e67f9f3 commit 18e0d49
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-moles-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/runtime": patch
---

Add DISABLE_JIT flag to disable GraphQL JIT
4 changes: 2 additions & 2 deletions examples/federation-example/gateway-supergraph/.meshrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ sources:
supergraph:
source: ./supergraph.graphql

documents:
- example-query.graphql
# documents:
# - example-query.graphql

serve:
playground: true
3 changes: 3 additions & 0 deletions examples/federation-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
"start": "concurrently \"npm:start-services npm:start-gateway-delayed\"",
"start-gateway": "mesh dev --dir gateway",
"start-gateway-delayed": "delay 1 && npm run start-gateway",
"start-gateway-supergraph": "mesh dev --dir gateway-supergraph",
"start-gateway-supergraph-delayed": "delay 1 && npm run start-gateway-supergraph",
"start-service-accounts": "ts-node services/accounts/index.ts",
"start-service-accounts-subgraph": "ts-node services/accounts-subgraph/index.ts",
"start-service-inventory": "ts-node services/inventory/index.ts",
"start-service-products": "ts-node services/products/index.ts",
"start-service-reviews": "ts-node services/reviews/index.ts",
"start-services": "concurrently \"npm:start-service-*\"",
"start-supergraph": "concurrently \"npm:start-services npm:start-gateway-supergraph-delayed\"",
"test": "jest"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/federation-example/services/inventory/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inspect } from 'node:util';
import { parse } from 'graphql';
import { ApolloServer } from '@apollo/server/';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';

Expand Down
2 changes: 1 addition & 1 deletion examples/federation-example/services/products/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from 'graphql';
import { ApolloServer } from '@apollo/server/';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';

Expand Down
2 changes: 1 addition & 1 deletion examples/federation-example/services/reviews/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from 'graphql';
import { ApolloServer } from '@apollo/server/';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';

Expand Down
4 changes: 3 additions & 1 deletion examples/federation-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
"rootDir": "./",
"esModuleInterop": true
}
},
"files": ["tests/federation-example.test.ts"]
}
30 changes: 20 additions & 10 deletions packages/legacy/runtime/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import { ASTNode, BREAK, getNamedType, GraphQLSchema, visit } from 'graphql';
import { getDocumentString } from '@envelop/core';
import { MapperKind, mapSchema, memoize1 } from '@graphql-tools/utils';

export const isStreamOperation = memoize1(function isStreamOperation(astNode: ASTNode): boolean {
if (globalThis.process?.env?.DISABLE_JIT) {
return true;
}
const documentStr = getDocumentString(astNode);
let isStream = false;
visit(astNode, {
Field: {
enter(node): typeof BREAK {
if (node.directives?.some(d => d.name.value === 'stream')) {
isStream = true;
return BREAK;
}
return undefined;
if (documentStr.includes('@stream')) {
visit(astNode, {
Field: {
enter(node): typeof BREAK {
if (node.directives?.some(d => d.name.value === 'stream')) {
isStream = true;
return BREAK;
}
return undefined;
},
},
},
});
});
}
return isStream;
});

export const isGraphQLJitCompatible = memoize1(function isGraphQLJitCompatible(
schema: GraphQLSchema,
) {
if (globalThis.process?.env?.DISABLE_JIT) {
return false;
}
let compatibleSchema = true;
mapSchema(schema, {
[MapperKind.INPUT_OBJECT_TYPE]: type => {
Expand Down

0 comments on commit 18e0d49

Please sign in to comment.