graphql-http 1.13.0 → 1.14.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/lib/handler.d.mts +14 -1
- package/lib/handler.d.ts +14 -1
- package/lib/handler.js +9 -2
- package/lib/handler.mjs +10 -3
- package/package.json +15 -15
- package/umd/graphql-http.min.js.gz +0 -0
package/lib/handler.d.mts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
6
|
+
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, ValidationRule, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
7
7
|
import { RequestParams } from './common';
|
|
8
8
|
/**
|
|
9
9
|
* The incoming request headers the implementing server should provide.
|
|
@@ -137,6 +137,19 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
137
137
|
* Will not be used when implementing a custom `onSubscribe`.
|
|
138
138
|
*/
|
|
139
139
|
validate?: typeof graphqlValidate;
|
|
140
|
+
/**
|
|
141
|
+
* The validation rules for running GraphQL validate.
|
|
142
|
+
*
|
|
143
|
+
* When providing an array, the rules will be APPENDED to the default
|
|
144
|
+
* `specifiedRules` array provided by the graphql-js module.
|
|
145
|
+
*
|
|
146
|
+
* Alternatively, providing a function instead will OVERWRITE the defaults
|
|
147
|
+
* and use exclusively the rules returned by the function. The third (last)
|
|
148
|
+
* argument of the function are the default `specifiedRules` array provided
|
|
149
|
+
* by the graphql-js module, you're free to prepend/append the defaults to
|
|
150
|
+
* your rule set, or omit them altogether.
|
|
151
|
+
*/
|
|
152
|
+
validationRules?: readonly ValidationRule[] | ((req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, specifiedRules: readonly ValidationRule[]) => Promise<readonly ValidationRule[]> | readonly ValidationRule[]);
|
|
140
153
|
/**
|
|
141
154
|
* Is the `execute` function from GraphQL which is
|
|
142
155
|
* used to execute the query and mutation operations.
|
package/lib/handler.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
6
|
+
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, ValidationRule, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
7
7
|
import { RequestParams } from './common';
|
|
8
8
|
/**
|
|
9
9
|
* The incoming request headers the implementing server should provide.
|
|
@@ -137,6 +137,19 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
137
137
|
* Will not be used when implementing a custom `onSubscribe`.
|
|
138
138
|
*/
|
|
139
139
|
validate?: typeof graphqlValidate;
|
|
140
|
+
/**
|
|
141
|
+
* The validation rules for running GraphQL validate.
|
|
142
|
+
*
|
|
143
|
+
* When providing an array, the rules will be APPENDED to the default
|
|
144
|
+
* `specifiedRules` array provided by the graphql-js module.
|
|
145
|
+
*
|
|
146
|
+
* Alternatively, providing a function instead will OVERWRITE the defaults
|
|
147
|
+
* and use exclusively the rules returned by the function. The third (last)
|
|
148
|
+
* argument of the function are the default `specifiedRules` array provided
|
|
149
|
+
* by the graphql-js module, you're free to prepend/append the defaults to
|
|
150
|
+
* your rule set, or omit them altogether.
|
|
151
|
+
*/
|
|
152
|
+
validationRules?: readonly ValidationRule[] | ((req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, specifiedRules: readonly ValidationRule[]) => Promise<readonly ValidationRule[]> | readonly ValidationRule[]);
|
|
140
153
|
/**
|
|
141
154
|
* Is the `execute` function from GraphQL which is
|
|
142
155
|
* used to execute the query and mutation operations.
|
package/lib/handler.js
CHANGED
|
@@ -76,7 +76,7 @@ exports.isResponse = isResponse;
|
|
|
76
76
|
* @category Server
|
|
77
77
|
*/
|
|
78
78
|
function createHandler(options) {
|
|
79
|
-
const { schema, context, validate = graphql_1.validate, execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
79
|
+
const { schema, context, validate = graphql_1.validate, validationRules = [], execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
80
80
|
return async function handler(req) {
|
|
81
81
|
var _a, _b;
|
|
82
82
|
const method = req.method;
|
|
@@ -226,7 +226,14 @@ function createHandler(options) {
|
|
|
226
226
|
else {
|
|
227
227
|
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema });
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
let rules = graphql_1.specifiedRules;
|
|
230
|
+
if (typeof validationRules === 'function') {
|
|
231
|
+
rules = await validationRules(req, args, graphql_1.specifiedRules);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
rules = [...rules, ...validationRules];
|
|
235
|
+
}
|
|
236
|
+
const validationErrs = validate(args.schema, args.document, rules);
|
|
230
237
|
if (validationErrs.length) {
|
|
231
238
|
return makeResponse(validationErrs, acceptedMediaType);
|
|
232
239
|
}
|
package/lib/handler.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
|
|
6
|
+
import { validate as graphqlValidate, specifiedRules, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
|
|
7
7
|
import { areGraphQLErrors, isAsyncIterable, isExecutionResult, isGraphQLError, isObject, } from './utils.mjs';
|
|
8
8
|
/**
|
|
9
9
|
* Checks whether the passed value is the `graphql-http` server agnostic response.
|
|
@@ -72,7 +72,7 @@ export function isResponse(val) {
|
|
|
72
72
|
* @category Server
|
|
73
73
|
*/
|
|
74
74
|
export function createHandler(options) {
|
|
75
|
-
const { schema, context, validate = graphqlValidate, execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
75
|
+
const { schema, context, validate = graphqlValidate, validationRules = [], execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
76
76
|
return async function handler(req) {
|
|
77
77
|
var _a, _b;
|
|
78
78
|
const method = req.method;
|
|
@@ -222,7 +222,14 @@ export function createHandler(options) {
|
|
|
222
222
|
else {
|
|
223
223
|
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema });
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
let rules = specifiedRules;
|
|
226
|
+
if (typeof validationRules === 'function') {
|
|
227
|
+
rules = await validationRules(req, args, specifiedRules);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
rules = [...rules, ...validationRules];
|
|
231
|
+
}
|
|
232
|
+
const validationErrs = validate(args.schema, args.document, rules);
|
|
226
233
|
if (validationErrs.length) {
|
|
227
234
|
return makeResponse(validationErrs, acceptedMediaType);
|
|
228
235
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=12"
|
|
26
26
|
},
|
|
27
|
-
"packageManager": "yarn@3.
|
|
27
|
+
"packageManager": "yarn@3.4.1",
|
|
28
28
|
"main": "lib/index.js",
|
|
29
29
|
"module": "lib/index.mjs",
|
|
30
30
|
"browser": "umd/graphql-http.js",
|
|
@@ -106,33 +106,33 @@
|
|
|
106
106
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
107
107
|
"@semantic-release/changelog": "^6.0.2",
|
|
108
108
|
"@semantic-release/git": "^10.0.1",
|
|
109
|
-
"@types/eslint": "^8.
|
|
110
|
-
"@types/express": "^4.17.
|
|
109
|
+
"@types/eslint": "^8.21.0",
|
|
110
|
+
"@types/express": "^4.17.17",
|
|
111
111
|
"@types/glob": "^8.0.1",
|
|
112
112
|
"@types/jest": "^29.4.0",
|
|
113
113
|
"@types/koa": "^2.13.5",
|
|
114
114
|
"@types/koa-mount": "^4.0.2",
|
|
115
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
116
|
-
"@typescript-eslint/parser": "^5.
|
|
117
|
-
"@whatwg-node/fetch": "^0.
|
|
118
|
-
"babel-jest": "^29.4.
|
|
119
|
-
"eslint": "^8.
|
|
115
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
116
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
117
|
+
"@whatwg-node/fetch": "^0.7.0",
|
|
118
|
+
"babel-jest": "^29.4.2",
|
|
119
|
+
"eslint": "^8.33.0",
|
|
120
120
|
"eslint-config-prettier": "^8.6.0",
|
|
121
121
|
"express": "^4.18.2",
|
|
122
122
|
"fastify": "^4.12.0",
|
|
123
123
|
"graphql": "^16.6.0",
|
|
124
|
-
"jest": "^29.4.
|
|
125
|
-
"jest-jasmine2": "^29.4.
|
|
124
|
+
"jest": "^29.4.2",
|
|
125
|
+
"jest-jasmine2": "^29.4.2",
|
|
126
126
|
"koa": "^2.14.1",
|
|
127
127
|
"koa-mount": "^4.0.0",
|
|
128
128
|
"node-fetch": "^3.3.0",
|
|
129
|
-
"prettier": "^2.8.
|
|
130
|
-
"rollup": "^3.
|
|
129
|
+
"prettier": "^2.8.4",
|
|
130
|
+
"rollup": "^3.14.0",
|
|
131
131
|
"semantic-release": "^20.1.0",
|
|
132
|
-
"tslib": "^2.
|
|
132
|
+
"tslib": "^2.5.0",
|
|
133
133
|
"typedoc": "^0.23.24",
|
|
134
134
|
"typedoc-plugin-markdown": "^3.14.0",
|
|
135
|
-
"typescript": "^4.9.
|
|
135
|
+
"typescript": "^4.9.5"
|
|
136
136
|
},
|
|
137
137
|
"resolutions": {
|
|
138
138
|
"npm/libnpmversion": "^3.0.6"
|
|
Binary file
|