Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit bc492e4

Browse files
committed
Do not pass parameters if we can't parse them.
1 parent 2819666 commit bc492e4

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/index.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,9 @@ function graphqlHTTP(options: Options): Middleware {
215215
// Then, resolve the Options to get OptionsData.
216216
return resolveOptions(params);
217217
},
218-
(error) => {
219-
// When we failed to parse the GraphQL parameters, we still need to get
220-
// the options object, so make an options call to resolve just that.
221-
const dummyParams = {
222-
query: null,
223-
variables: null,
224-
operationName: null,
225-
raw: null,
226-
};
227-
return resolveOptions(dummyParams).then(() => Promise.reject(error));
228-
},
218+
// When we failed to parse the GraphQL parameters, we still need to get
219+
// the options object, so make an options call to resolve just that.
220+
(error) => resolveOptions().then(() => Promise.reject(error)),
229221
)
230222
.then((optionsData) => {
231223
// Assert that schema is required.
@@ -402,7 +394,7 @@ function graphqlHTTP(options: Options): Middleware {
402394
}
403395
});
404396

405-
async function resolveOptions(requestParams) {
397+
async function resolveOptions(requestParams?: GraphQLParams) {
406398
const optionsResult =
407399
typeof options === 'function'
408400
? options(request, response, requestParams)
@@ -438,10 +430,10 @@ function graphqlHTTP(options: Options): Middleware {
438430
}
439431

440432
export type GraphQLParams = {|
441-
query: ?string,
442-
variables: ?{ +[name: string]: mixed, ... },
443-
operationName: ?string,
444-
raw: ?boolean,
433+
query: string | null,
434+
variables: { +[name: string]: mixed, ... } | null,
435+
operationName: string | null,
436+
raw: boolean,
445437
|};
446438

447439
/**
@@ -496,9 +488,8 @@ function parseGraphQLParams(
496488
* Helper function to determine if GraphiQL can be displayed.
497489
*/
498490
function canDisplayGraphiQL(request: $Request, params: GraphQLParams): boolean {
499-
// If `raw` exists, GraphiQL mode is not enabled.
500-
// Allowed to show GraphiQL if not requested as raw and this request
501-
// prefers HTML over JSON.
491+
// If `raw` false, GraphiQL mode is not enabled.
492+
// Allowed to show GraphiQL if not requested as raw and this request prefers HTML over JSON.
502493
return !params.raw && accepts(request).types(['json', 'html']) === 'html';
503494
}
504495

types/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ declare namespace graphqlHTTP {
185185
) => Promise<undefined>;
186186

187187
interface GraphQLParams {
188-
query: string | null | undefined;
189-
variables: { readonly [name: string]: unknown } | null | undefined;
190-
operationName: string | null | undefined;
191-
raw: boolean | null | undefined;
188+
query: string | null;
189+
variables: { readonly [name: string]: unknown } | null;
190+
operationName: string | null;
191+
raw: boolean | null;
192192
}
193193
}
194194

0 commit comments

Comments
 (0)