Skip to content

Commit 44d0c60

Browse files
authored
fix incremental delivery in test graphiql server (#3978)
* fix test graphiql server * fix * upd * cleanup legacy files * fix one e2e test * here we gooo * fix lint and remove unused deps * try this if netlify works * try helix in netlify * log error * try * rm graphql dep * rm graphql dep * rollback to use graphql-http
1 parent c753d96 commit 44d0c60

22 files changed

+459
-724
lines changed

functions/graphql.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import {
33
HandlerOptions as RawHandlerOptions,
44
OperationContext,
55
} from 'graphql-http';
6-
76
import type {
87
Handler as NetlifyHandler,
98
HandlerEvent as NetlifyHandlerEvent,
109
HandlerContext as NetlifyHandlerContext,
1110
} from '@netlify/functions';
12-
13-
import { testSchema } from '../packages/graphiql/test/schema.js';
14-
import { customExecute } from '../packages/graphiql/test/execute.js';
11+
import * as graphql from 'graphql';
12+
import { createSchema } from '../packages/graphiql/test/schema.js';
13+
import { createExecute } from '../packages/graphiql/test/execute.js';
1514

1615
/**
1716
* Handler options when using the netlify adapter
1817
*
1918
* @category Server/@netlify/functions
2019
*/
21-
export type HandlerOptions<Context extends OperationContext = undefined> =
20+
type HandlerOptions<Context extends OperationContext = undefined> =
2221
RawHandlerOptions<NetlifyHandlerEvent, NetlifyHandlerContext, Context>;
2322

2423
/**
@@ -52,12 +51,15 @@ export function createHandler<Context extends OperationContext = undefined>(
5251
'Internal error occurred during request handling. Please check your implementation.',
5352
err,
5453
);
55-
return { statusCode: 500 };
54+
return {
55+
statusCode: 500,
56+
body: JSON.stringify({ errors: [{ message: err.message }] }),
57+
};
5658
}
5759
};
5860
}
5961

6062
export const handler = createHandler({
61-
schema: testSchema,
62-
execute: customExecute,
63+
schema: createSchema(graphql),
64+
execute: createExecute(graphql),
6365
});

functions/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "netlify-function",
3+
"private": true,
4+
"dependencies": {
5+
"graphql": "^16.11.0",
6+
"graphql-http": "^1.22.4"
7+
}
8+
}

jest.config.base.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
const path = require('node:path');
2-
3-
module.exports = (dir, env = 'jsdom') => {
1+
module.exports = dir => {
42
const package = require(`${dir}/package.json`);
5-
const setupFilesAfterEnv = [];
6-
if (env === 'jsdom') {
7-
setupFilesAfterEnv.push(path.join(__dirname, '/resources/test.config.js'));
8-
}
93
return {
104
globals: {
115
'ts-jest': {
@@ -15,21 +9,14 @@ module.exports = (dir, env = 'jsdom') => {
159
clearMocks: true,
1610
collectCoverage: true,
1711
coverageDirectory: `${__dirname}/coverage/jest`,
18-
setupFilesAfterEnv,
1912
moduleNameMapper: {
20-
'\\.css$': 'identity-obj-proxy',
2113
'^graphql-language-service-([^/]+)': `${__dirname}/packages/graphql-language-service/src/$1`,
2214
'^graphql-language-([^/]+)': `${__dirname}/packages/graphql-language-$1/src`,
23-
'^@graphiql\\/([^/]+)': `${__dirname}/packages/graphiql-$1/src`,
24-
'^codemirror-graphql\\/esm([^]+)\\.js': `${__dirname}/packages/codemirror-graphql/src/$1`,
25-
'^codemirror-graphql\\/cjs([^]+)': `${__dirname}/packages/codemirror-graphql/src/$1`,
26-
// relies on compilation
27-
'^cm6-graphql\\/src\\/([^]+)': `${__dirname}/packages/cm6-graphql/dist/$1`,
2815
// because of the svelte compiler's export patterns i guess?
2916
'svelte/compiler': `${__dirname}/node_modules/svelte/compiler.cjs`,
3017
},
3118
testMatch: ['**/*[-.](spec|test).[jt]s?(x)', '!**/cypress/**'],
32-
testEnvironment: env,
19+
testEnvironment: 'node',
3320
testPathIgnorePatterns: ['node_modules', 'dist', 'cypress'],
3421
collectCoverageFrom: ['**/src/**/*.{js,jsx,ts,tsx}'],
3522
transformIgnorePatterns: ['node_modules/(!@astrojs/compiler)'],

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"workspaces": {
77
"packages": [
88
"packages/*",
9+
"functions",
10+
"packages/graphiql/test",
911
"examples/monaco-graphql-webpack",
1012
"examples/monaco-graphql-nextjs",
1113
"examples/monaco-graphql-react-vite",
@@ -87,7 +89,6 @@
8789
"@types/ws": "8.2.2",
8890
"@typescript-eslint/eslint-plugin": "^8.32.0",
8991
"@typescript-eslint/parser": "^8.32.0",
90-
"babel-jest": "^29.4.3",
9192
"babel-plugin-macros": "^3.1.0",
9293
"babel-plugin-transform-import-meta": "^2.2.1",
9394
"concurrently": "^7.0.0",
@@ -107,8 +108,6 @@
107108
"eslint-plugin-unicorn": "^56.0.0",
108109
"execa": "^7.1.1",
109110
"fetch-mock": "6.5.2",
110-
"graphql-http": "^1.22.1",
111-
"identity-obj-proxy": "^3.0.0",
112111
"jest": "^27.5.1",
113112
"js-green-licenses": "4.0.0",
114113
"mkdirp": "^1.0.4",

packages/graphiql/cypress/e2e/incremental-delivery.cy.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// import { version } from 'graphql';
1+
import { version } from 'graphql';
22

33
let describeOrSkip: Mocha.SuiteFunction | Mocha.PendingSuiteFunction = describe;
4-
// TODO: add support to graphql-http for IncrementalDelivery first
5-
// if (parseInt(version, 10) < 17) {
64

7-
describeOrSkip = describe.skip;
8-
// }
5+
if (parseInt(version, 10) < 17) {
6+
describeOrSkip = describe.skip;
7+
}
98

109
describeOrSkip('IncrementalDelivery support via fetcher', () => {
1110
describe('When operation contains @stream', () => {
@@ -20,36 +19,16 @@ describeOrSkip('IncrementalDelivery support via fetcher', () => {
2019
const mockStreamSuccess = {
2120
data: {
2221
streamable: [
23-
{
24-
text: 'Hi',
25-
},
26-
{
27-
text: '你好',
28-
},
29-
{
30-
text: 'Hola',
31-
},
32-
{
33-
text: 'أهلاً',
34-
},
35-
{
36-
text: 'Bonjour',
37-
},
38-
{
39-
text: 'سلام',
40-
},
41-
{
42-
text: '안녕',
43-
},
44-
{
45-
text: 'Ciao',
46-
},
47-
{
48-
text: 'हेलो',
49-
},
50-
{
51-
text: 'Здорово',
52-
},
22+
{ text: 'Hi' },
23+
{ text: '你好' },
24+
{ text: 'Hola' },
25+
{ text: 'أهلاً' },
26+
{ text: 'Bonjour' },
27+
{ text: 'سلام' },
28+
{ text: '안녕' },
29+
{ text: 'Ciao' },
30+
{ text: 'हेलो' },
31+
{ text: 'Здорово' },
5332
],
5433
},
5534
};
@@ -142,22 +121,10 @@ describeOrSkip('IncrementalDelivery support via fetcher', () => {
142121
person: {
143122
name: 'Mark',
144123
friends: [
145-
{
146-
name: 'James',
147-
age: 1000,
148-
},
149-
{
150-
name: 'Mary',
151-
age: 1000,
152-
},
153-
{
154-
name: 'John',
155-
age: 1000,
156-
},
157-
{
158-
name: 'Patrica',
159-
age: 1000,
160-
},
124+
{ name: 'James', age: 1000 },
125+
{ name: 'Mary', age: 1000 },
126+
{ name: 'John', age: 1000 },
127+
{ name: 'Patrica', age: 1000 },
161128
],
162129
age: 1000,
163130
},

packages/graphiql/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,13 @@
6565
"babel-plugin-react-compiler": "19.1.0-rc.1",
6666
"cross-env": "^7.0.2",
6767
"cypress": "^13.13.2",
68-
"express": "^4.20.0",
6968
"graphql": "^16.11.0",
70-
"graphql-helix": "^1.13.0",
71-
"graphql-subscriptions": "^2.0.0",
7269
"lightningcss": "^1.29.3",
7370
"react": "^19.1.0",
7471
"react-dom": "^19.1.0",
7572
"start-server-and-test": "^1.10.11",
76-
"subscriptions-transport-ws": "0.11.0",
7773
"typescript": "^4.6.3",
7874
"vite": "^6.3.4",
79-
"vite-plugin-dts": "^4.5.3",
80-
"ws": "8.17.1"
75+
"vite-plugin-dts": "^4.5.3"
8176
}
8277
}

packages/graphiql/test/e2e-server.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
/* eslint-disable no-console, import-x/no-extraneous-dependencies */
8+
/* eslint-disable no-console */
99
import { createServer } from 'node:http';
1010
import path from 'node:path';
1111
import { fileURLToPath } from 'node:url';
1212
import express from 'express';
13-
import { useServer } from 'graphql-ws/lib/use/ws';
13+
import { useServer } from 'graphql-ws/use/ws';
1414
import { WebSocketServer } from 'ws';
1515
import {
1616
getGraphQLParameters,
1717
processRequest,
1818
sendResult,
1919
} from 'graphql-helix'; // update when `graphql-http` is upgraded to support multipart requests for incremental delivery https://github.com/graphql/graphiql/pull/3682#discussion_r1715545279
20+
import * as graphql from 'graphql';
2021

21-
import { testSchema as schema } from './schema.js';
22-
import { customExecute } from './execute.js';
22+
import { createSchema } from './schema.js';
23+
import { createExecute } from './execute.js';
24+
25+
const schema = createSchema(graphql);
26+
const customExecute = createExecute(graphql);
2327

2428
const app = express();
2529

@@ -44,6 +48,7 @@ async function handler(req, res) {
4448

4549
sendResult(result, res);
4650
}
51+
4752
// Server
4853
app.use(express.json());
4954

packages/graphiql/test/execute.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
/* eslint-disable import-x/no-extraneous-dependencies, import-x/default */
2-
import pkg from 'graphql';
3-
const { execute, experimentalExecuteIncrementally, version } = pkg;
1+
export function createExecute({
2+
execute,
3+
experimentalExecuteIncrementally,
4+
version,
5+
}) {
6+
if (parseInt(version, 10) < 17) {
7+
return execute;
8+
}
9+
return async (...args) => {
10+
const result = await experimentalExecuteIncrementally(...args);
411

5-
export const customExecute =
6-
parseInt(version, 10) > 16
7-
? async (...args) => {
8-
const result = await experimentalExecuteIncrementally(...args);
12+
if (!('subsequentResults' in result)) {
13+
return result;
14+
}
915

10-
if (!('subsequentResults' in result)) {
11-
return result;
12-
}
16+
const { initialResult, subsequentResults } = result;
17+
if (typeof subsequentResults[Symbol.asyncIterator] !== 'function') {
18+
return result;
19+
}
1320

14-
const { initialResult, subsequentResults } = result;
15-
if (typeof subsequentResults[Symbol.asyncIterator] !== 'function') {
16-
return result;
17-
}
18-
19-
return (async function* () {
20-
yield initialResult;
21-
yield* subsequentResults;
22-
})();
23-
}
24-
: execute;
21+
return (async function* () {
22+
yield initialResult;
23+
yield* subsequentResults;
24+
})();
25+
};
26+
}

packages/graphiql/test/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"type": "module"
2+
"type": "module",
3+
"name": "test-server",
4+
"private": true,
5+
"dependencies": {
6+
"express": "^4.20.0",
7+
"graphql": "^17.0.0-alpha.8",
8+
"graphql-helix": "^1.13.0",
9+
"graphql-ws": "^6.0.5",
10+
"ws": "8.17.1"
11+
}
312
}

0 commit comments

Comments
 (0)