Skip to content

Commit d10acda

Browse files
authored
internal: fix inlineInvariant for cjs builds that require filenames with explicit extensions (#3832)
1 parent 3efdc54 commit d10acda

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

integrationTests/node/index.cjs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const assert = require('assert');
22
const { readFileSync } = require('fs');
33

4-
const { graphqlSync } = require('graphql');
4+
const {
5+
experimentalExecuteIncrementally,
6+
graphqlSync,
7+
parse,
8+
} = require('graphql');
59
const { buildSchema } = require('graphql/utilities');
610
const { version } = require('graphql/version');
711

@@ -12,7 +16,7 @@ assert.deepStrictEqual(
1216

1317
const schema = buildSchema('type Query { hello: String }');
1418

15-
const result = graphqlSync({
19+
let result = graphqlSync({
1620
schema,
1721
source: '{ hello }',
1822
rootValue: { hello: 'world' },
@@ -24,3 +28,27 @@ assert.deepStrictEqual(result, {
2428
hello: 'world',
2529
},
2630
});
31+
32+
/**
33+
* The below test triggers a call `invariant` method during execution (by
34+
* passing a negative number to the `initialCount` parameter on the `@stream`
35+
* directive). This ensures that the `inlineInvariant` method called by our
36+
* build script works correctly.
37+
**/
38+
39+
const experimentalSchema = buildSchema(`
40+
directive @stream(initialCount: Int!) on FIELD
41+
42+
type Query {
43+
greetings: [String]
44+
}
45+
`);
46+
47+
result = experimentalExecuteIncrementally({
48+
schema: experimentalSchema,
49+
document: parse('{ greetings @stream(initialCount: -1) }'),
50+
rootValue: { greetings: ['hi', 'hello'] },
51+
});
52+
53+
assert(result.errors?.[0] !== undefined);
54+
assert(!result.errors[0].message.includes('is not defined'));

integrationTests/node/index.mjs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import assert from 'assert';
33
import { readFileSync } from 'fs';
44

5-
import { graphqlSync } from 'graphql-esm';
5+
import {
6+
experimentalExecuteIncrementally,
7+
graphqlSync,
8+
parse,
9+
} from 'graphql-esm';
610
import { buildSchema } from 'graphql-esm/utilities';
711
import { version } from 'graphql-esm/version';
812

@@ -13,7 +17,7 @@ assert.deepStrictEqual(
1317

1418
const schema = buildSchema('type Query { hello: String }');
1519

16-
const result = graphqlSync({
20+
let result = graphqlSync({
1721
schema,
1822
source: '{ hello }',
1923
rootValue: { hello: 'world' },
@@ -25,3 +29,27 @@ assert.deepStrictEqual(result, {
2529
hello: 'world',
2630
},
2731
});
32+
33+
/**
34+
* The below test triggers a call `invariant` method during execution (by
35+
* passing a negative number to the `initialCount` parameter on the `@stream`
36+
* directive). This ensures that the `inlineInvariant` method called by our
37+
* build script works correctly.
38+
**/
39+
40+
const experimentalSchema = buildSchema(`
41+
directive @stream(initialCount: Int!) on FIELD
42+
43+
type Query {
44+
greetings: [String]
45+
}
46+
`);
47+
48+
result = experimentalExecuteIncrementally({
49+
schema: experimentalSchema,
50+
document: parse('{ greetings @stream(initialCount: -1) }'),
51+
rootValue: { greetings: ['hi', 'hello'] },
52+
});
53+
54+
assert(result.errors?.[0] !== undefined);
55+
assert(!result.errors[0].message.includes('is not defined'));

resources/inline-invariant.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ export function inlineInvariant(context: ts.TransformationContext) {
3232
return factory.createBinaryExpression(
3333
factory.createParenthesizedExpression(condition),
3434
ts.SyntaxKind.BarBarToken,
35-
factory.createCallExpression(
36-
factory.createIdentifier(funcName),
37-
undefined,
38-
[factory.createFalse(), ...otherArgs],
39-
),
35+
factory.createCallExpression(expression, undefined, [
36+
factory.createFalse(),
37+
...otherArgs,
38+
]),
4039
);
4140
}
4241
}

0 commit comments

Comments
 (0)