graphql-yoga 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/plugins/request-validation/use-check-graphql-query-params.js +8 -5
- package/cjs/server.js +1 -1
- package/esm/plugins/request-validation/use-check-graphql-query-params.js +8 -5
- package/esm/server.js +1 -1
- package/package.json +1 -1
- package/typings/plugins/request-validation/use-check-graphql-query-params.d.cts +3 -3
- package/typings/plugins/request-validation/use-check-graphql-query-params.d.ts +3 -3
- package/typings/server.d.cts +10 -0
- package/typings/server.d.ts +10 -0
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useCheckGraphQLQueryParams = exports.isValidGraphQLParams = exports.checkGraphQLQueryParams = exports.assertInvalidParams = void 0;
|
|
4
4
|
const utils_1 = require("@graphql-tools/utils");
|
|
5
5
|
const expectedParameters = new Set(['query', 'variables', 'operationName', 'extensions']);
|
|
6
|
-
function assertInvalidParams(params) {
|
|
6
|
+
function assertInvalidParams(params, extraParamNames) {
|
|
7
7
|
if (params == null || typeof params !== 'object') {
|
|
8
8
|
throw (0, utils_1.createGraphQLError)('Invalid "params" in the request body', {
|
|
9
9
|
extensions: {
|
|
@@ -19,6 +19,9 @@ function assertInvalidParams(params) {
|
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
21
|
if (!expectedParameters.has(paramKey)) {
|
|
22
|
+
if (extraParamNames?.includes(paramKey)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
22
25
|
throw (0, utils_1.createGraphQLError)(`Unexpected parameter "${paramKey}" in the request body.`, {
|
|
23
26
|
extensions: {
|
|
24
27
|
http: {
|
|
@@ -30,7 +33,7 @@ function assertInvalidParams(params) {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
exports.assertInvalidParams = assertInvalidParams;
|
|
33
|
-
function checkGraphQLQueryParams(params) {
|
|
36
|
+
function checkGraphQLQueryParams(params, extraParamNames) {
|
|
34
37
|
if (!isObject(params)) {
|
|
35
38
|
throw (0, utils_1.createGraphQLError)(`Expected params to be an object but given ${extendedTypeof(params)}.`, {
|
|
36
39
|
extensions: {
|
|
@@ -43,7 +46,7 @@ function checkGraphQLQueryParams(params) {
|
|
|
43
46
|
},
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
|
-
assertInvalidParams(params);
|
|
49
|
+
assertInvalidParams(params, extraParamNames);
|
|
47
50
|
if (params.query == null) {
|
|
48
51
|
throw (0, utils_1.createGraphQLError)('Must provide query string.', {
|
|
49
52
|
extensions: {
|
|
@@ -109,10 +112,10 @@ function isValidGraphQLParams(params) {
|
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
exports.isValidGraphQLParams = isValidGraphQLParams;
|
|
112
|
-
function useCheckGraphQLQueryParams() {
|
|
115
|
+
function useCheckGraphQLQueryParams(extraParamNames) {
|
|
113
116
|
return {
|
|
114
117
|
onParams({ params }) {
|
|
115
|
-
checkGraphQLQueryParams(params);
|
|
118
|
+
checkGraphQLQueryParams(params, extraParamNames);
|
|
116
119
|
},
|
|
117
120
|
};
|
|
118
121
|
}
|
package/cjs/server.js
CHANGED
|
@@ -185,7 +185,7 @@ class YogaServer {
|
|
|
185
185
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
|
186
186
|
addPlugin((0, use_limit_batching_js_1.useLimitBatching)(batchingLimit));
|
|
187
187
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
|
188
|
-
addPlugin((0, use_check_graphql_query_params_js_1.useCheckGraphQLQueryParams)());
|
|
188
|
+
addPlugin((0, use_check_graphql_query_params_js_1.useCheckGraphQLQueryParams)(options?.extraParamNames));
|
|
189
189
|
const showLandingPage = !!(options?.landingPage ?? true);
|
|
190
190
|
addPlugin(
|
|
191
191
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createGraphQLError } from '@graphql-tools/utils';
|
|
2
2
|
const expectedParameters = new Set(['query', 'variables', 'operationName', 'extensions']);
|
|
3
|
-
export function assertInvalidParams(params) {
|
|
3
|
+
export function assertInvalidParams(params, extraParamNames) {
|
|
4
4
|
if (params == null || typeof params !== 'object') {
|
|
5
5
|
throw createGraphQLError('Invalid "params" in the request body', {
|
|
6
6
|
extensions: {
|
|
@@ -16,6 +16,9 @@ export function assertInvalidParams(params) {
|
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
18
|
if (!expectedParameters.has(paramKey)) {
|
|
19
|
+
if (extraParamNames?.includes(paramKey)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
19
22
|
throw createGraphQLError(`Unexpected parameter "${paramKey}" in the request body.`, {
|
|
20
23
|
extensions: {
|
|
21
24
|
http: {
|
|
@@ -26,7 +29,7 @@ export function assertInvalidParams(params) {
|
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
export function checkGraphQLQueryParams(params) {
|
|
32
|
+
export function checkGraphQLQueryParams(params, extraParamNames) {
|
|
30
33
|
if (!isObject(params)) {
|
|
31
34
|
throw createGraphQLError(`Expected params to be an object but given ${extendedTypeof(params)}.`, {
|
|
32
35
|
extensions: {
|
|
@@ -39,7 +42,7 @@ export function checkGraphQLQueryParams(params) {
|
|
|
39
42
|
},
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
|
-
assertInvalidParams(params);
|
|
45
|
+
assertInvalidParams(params, extraParamNames);
|
|
43
46
|
if (params.query == null) {
|
|
44
47
|
throw createGraphQLError('Must provide query string.', {
|
|
45
48
|
extensions: {
|
|
@@ -103,10 +106,10 @@ export function isValidGraphQLParams(params) {
|
|
|
103
106
|
return false;
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
export function useCheckGraphQLQueryParams() {
|
|
109
|
+
export function useCheckGraphQLQueryParams(extraParamNames) {
|
|
107
110
|
return {
|
|
108
111
|
onParams({ params }) {
|
|
109
|
-
checkGraphQLQueryParams(params);
|
|
112
|
+
checkGraphQLQueryParams(params, extraParamNames);
|
|
110
113
|
},
|
|
111
114
|
};
|
|
112
115
|
}
|
package/esm/server.js
CHANGED
|
@@ -181,7 +181,7 @@ export class YogaServer {
|
|
|
181
181
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
|
182
182
|
addPlugin(useLimitBatching(batchingLimit));
|
|
183
183
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
|
184
|
-
addPlugin(useCheckGraphQLQueryParams());
|
|
184
|
+
addPlugin(useCheckGraphQLQueryParams(options?.extraParamNames));
|
|
185
185
|
const showLandingPage = !!(options?.landingPage ?? true);
|
|
186
186
|
addPlugin(
|
|
187
187
|
// @ts-expect-error Add plugins has context but this hook doesn't care
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLParams } from '../../types.cjs';
|
|
2
2
|
import type { Plugin } from '../types.cjs';
|
|
3
|
-
export declare function assertInvalidParams(params: unknown): asserts params is GraphQLParams;
|
|
4
|
-
export declare function checkGraphQLQueryParams(params: unknown): GraphQLParams;
|
|
3
|
+
export declare function assertInvalidParams(params: unknown, extraParamNames?: string[]): asserts params is GraphQLParams;
|
|
4
|
+
export declare function checkGraphQLQueryParams(params: unknown, extraParamNames?: string[]): GraphQLParams;
|
|
5
5
|
export declare function isValidGraphQLParams(params: unknown): params is GraphQLParams;
|
|
6
|
-
export declare function useCheckGraphQLQueryParams(): Plugin;
|
|
6
|
+
export declare function useCheckGraphQLQueryParams(extraParamNames?: string[]): Plugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLParams } from '../../types.js';
|
|
2
2
|
import type { Plugin } from '../types.js';
|
|
3
|
-
export declare function assertInvalidParams(params: unknown): asserts params is GraphQLParams;
|
|
4
|
-
export declare function checkGraphQLQueryParams(params: unknown): GraphQLParams;
|
|
3
|
+
export declare function assertInvalidParams(params: unknown, extraParamNames?: string[]): asserts params is GraphQLParams;
|
|
4
|
+
export declare function checkGraphQLQueryParams(params: unknown, extraParamNames?: string[]): GraphQLParams;
|
|
5
5
|
export declare function isValidGraphQLParams(params: unknown): params is GraphQLParams;
|
|
6
|
-
export declare function useCheckGraphQLQueryParams(): Plugin;
|
|
6
|
+
export declare function useCheckGraphQLQueryParams(extraParamNames?: string[]): Plugin;
|
package/typings/server.d.cts
CHANGED
|
@@ -81,6 +81,16 @@ export type YogaServerOptions<TServerContext, TUserContext> = {
|
|
|
81
81
|
* @default false
|
|
82
82
|
*/
|
|
83
83
|
batching?: BatchingOptions | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* By default, GraphQL Yoga does not allow parameters in the request body except `query`, `variables`, `extensions`, and `operationName`.
|
|
86
|
+
*
|
|
87
|
+
* This option allows you to specify additional parameters that are allowed in the request body.
|
|
88
|
+
*
|
|
89
|
+
* @default []
|
|
90
|
+
*
|
|
91
|
+
* @example ['doc_id', 'id']
|
|
92
|
+
*/
|
|
93
|
+
extraParamNames?: string[] | undefined;
|
|
84
94
|
};
|
|
85
95
|
export type BatchingOptions = boolean | {
|
|
86
96
|
/**
|
package/typings/server.d.ts
CHANGED
|
@@ -81,6 +81,16 @@ export type YogaServerOptions<TServerContext, TUserContext> = {
|
|
|
81
81
|
* @default false
|
|
82
82
|
*/
|
|
83
83
|
batching?: BatchingOptions | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* By default, GraphQL Yoga does not allow parameters in the request body except `query`, `variables`, `extensions`, and `operationName`.
|
|
86
|
+
*
|
|
87
|
+
* This option allows you to specify additional parameters that are allowed in the request body.
|
|
88
|
+
*
|
|
89
|
+
* @default []
|
|
90
|
+
*
|
|
91
|
+
* @example ['doc_id', 'id']
|
|
92
|
+
*/
|
|
93
|
+
extraParamNames?: string[] | undefined;
|
|
84
94
|
};
|
|
85
95
|
export type BatchingOptions = boolean | {
|
|
86
96
|
/**
|