Skip to content

Commit 564b761

Browse files
authored
fix netlify graphql function (#3721)
1 parent 5f000ed commit 564b761

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

functions/graphql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
} from '@netlify/functions';
1212

1313
import schema from '../packages/graphiql/test/schema';
14+
import { customExecute } from '../packages/graphiql/test/execute';
1415

1516
/**
1617
* Handler options when using the netlify adapter
@@ -48,13 +49,12 @@ export function createHandler<Context extends OperationContext = undefined>(
4849
// The handler shouldn't throw errors.
4950
// If you wish to handle them differently, consider implementing your own request handler.
5051
console.error(
51-
'Internal error occurred during request handling. ' +
52-
'Please check your implementation.',
52+
'Internal error occurred during request handling. Please check your implementation.',
5353
err,
5454
);
5555
return { statusCode: 500 };
5656
}
5757
};
5858
}
5959

60-
export const handler = createHandler({ schema });
60+
export const handler = createHandler({ schema, execute: customExecute });

packages/graphiql/test/e2e-server.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,16 @@
99
const { createServer } = require('node:http');
1010
const express = require('express');
1111
const path = require('node:path');
12-
const {
13-
execute,
14-
experimentalExecuteIncrementally,
15-
version,
16-
} = require('graphql');
17-
const schema = require('./schema');
18-
const app = express();
1912
const {
2013
getGraphQLParameters,
2114
processRequest,
2215
sendResult,
2316
} = require('graphql-helix'); // update when `graphql-http` is upgraded to support multipart requests for incremental delivery https://github.com/graphql/graphiql/pull/3682#discussion_r1715545279
2417
const WebSocketsServer = require('./afterDevServer');
18+
const schema = require('./schema');
19+
const { customExecute } = require('./execute');
2520

26-
const customExecute =
27-
parseInt(version, 10) > 16
28-
? async (...args) => {
29-
const result = await experimentalExecuteIncrementally(...args);
30-
31-
if (!('subsequentResults' in result)) {
32-
return result;
33-
}
34-
35-
const { initialResult, subsequentResults } = result;
36-
if (typeof subsequentResults[Symbol.asyncIterator] !== 'function') {
37-
return result;
38-
}
39-
40-
return (async function* () {
41-
yield initialResult;
42-
yield* subsequentResults;
43-
})();
44-
}
45-
: execute;
21+
const app = express();
4622

4723
async function handler(req, res) {
4824
const request = {

packages/graphiql/test/execute.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const {
2+
execute,
3+
experimentalExecuteIncrementally,
4+
version,
5+
} = require('graphql');
6+
7+
const customExecute =
8+
parseInt(version, 10) > 16
9+
? async (...args) => {
10+
const result = await experimentalExecuteIncrementally(...args);
11+
12+
if (!('subsequentResults' in result)) {
13+
return result;
14+
}
15+
16+
const { initialResult, subsequentResults } = result;
17+
if (typeof subsequentResults[Symbol.asyncIterator] !== 'function') {
18+
return result;
19+
}
20+
21+
return (async function* () {
22+
yield initialResult;
23+
yield* subsequentResults;
24+
})();
25+
}
26+
: execute;
27+
28+
module.exports = { customExecute };

0 commit comments

Comments
 (0)