graphql-http 1.2.0 → 1.5.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/README.md +52 -26
- package/lib/audits/common.d.ts +58 -0
- package/lib/audits/common.js +7 -0
- package/lib/audits/common.mjs +6 -0
- package/lib/audits/index.d.ts +2 -0
- package/lib/audits/index.js +18 -0
- package/lib/audits/index.mjs +2 -0
- package/lib/audits/server.d.ts +39 -0
- package/lib/audits/server.js +400 -0
- package/lib/audits/server.mjs +395 -0
- package/lib/audits/utils.d.ts +27 -0
- package/lib/audits/utils.js +100 -0
- package/lib/audits/utils.mjs +81 -0
- package/lib/client.js +2 -2
- package/lib/client.mjs +2 -2
- package/lib/handler.d.ts +9 -3
- package/lib/handler.js +18 -13
- package/lib/handler.mjs +18 -13
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/lib/utils.d.ts +3 -1
- package/lib/utils.js +12 -1
- package/lib/utils.mjs +10 -0
- package/package.json +15 -15
- package/umd/graphql-http.js +2 -2
- package/umd/graphql-http.min.js +1 -1
- package/umd/graphql-http.min.js.gz +0 -0
package/lib/handler.js
CHANGED
|
@@ -55,7 +55,7 @@ exports.isResponse = isResponse;
|
|
|
55
55
|
* url: req.url,
|
|
56
56
|
* method: req.method,
|
|
57
57
|
* headers: req.headers,
|
|
58
|
-
* body:
|
|
58
|
+
* body: () => new Promise((resolve) => {
|
|
59
59
|
* let body = '';
|
|
60
60
|
* req.on('data', (chunk) => (body += chunk));
|
|
61
61
|
* req.on('end', () => resolve(body));
|
|
@@ -100,7 +100,7 @@ function createHandler(options) {
|
|
|
100
100
|
status: 406,
|
|
101
101
|
statusText: 'Not Acceptable',
|
|
102
102
|
headers: {
|
|
103
|
-
accept: 'application/graphql+json; charset=utf-8, application/json; charset=utf-8',
|
|
103
|
+
accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
];
|
|
@@ -142,16 +142,21 @@ function createHandler(options) {
|
|
|
142
142
|
if (!req.body) {
|
|
143
143
|
throw new Error('Missing body');
|
|
144
144
|
}
|
|
145
|
+
let data;
|
|
145
146
|
try {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
partParams.query = data.query;
|
|
149
|
-
partParams.variables = data.variables;
|
|
150
|
-
partParams.extensions = data.extensions;
|
|
147
|
+
const body = typeof req.body === 'function' ? await req.body() : req.body;
|
|
148
|
+
data = typeof body === 'string' ? JSON.parse(body) : body;
|
|
151
149
|
}
|
|
152
|
-
catch (
|
|
150
|
+
catch (err) {
|
|
153
151
|
throw new Error('Unparsable JSON body');
|
|
154
152
|
}
|
|
153
|
+
if (!(0, utils_1.isObject)(data)) {
|
|
154
|
+
throw new Error('JSON body must be an object');
|
|
155
|
+
}
|
|
156
|
+
partParams.operationName = data.operationName;
|
|
157
|
+
partParams.query = data.query;
|
|
158
|
+
partParams.variables = data.variables;
|
|
159
|
+
partParams.extensions = data.extensions;
|
|
155
160
|
break;
|
|
156
161
|
}
|
|
157
162
|
default: // graphql-http doesnt support any other content type
|
|
@@ -229,7 +234,7 @@ function createHandler(options) {
|
|
|
229
234
|
throw null;
|
|
230
235
|
operation = ast.operation;
|
|
231
236
|
}
|
|
232
|
-
catch (
|
|
237
|
+
catch (_d) {
|
|
233
238
|
return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType);
|
|
234
239
|
}
|
|
235
240
|
if (operation === 'subscription') {
|
|
@@ -291,11 +296,11 @@ function getAcceptableMediaType(acceptHeader) {
|
|
|
291
296
|
acceptedMediaType = 'application/json';
|
|
292
297
|
break;
|
|
293
298
|
}
|
|
294
|
-
if ((mediaType === 'application/graphql+json' ||
|
|
299
|
+
if ((mediaType === 'application/graphql-response+json' ||
|
|
295
300
|
mediaType === 'application/*' ||
|
|
296
301
|
mediaType === '*/*') &&
|
|
297
302
|
charset === 'charset=utf8') {
|
|
298
|
-
acceptedMediaType = 'application/graphql+json';
|
|
303
|
+
acceptedMediaType = 'application/graphql-response+json';
|
|
299
304
|
break;
|
|
300
305
|
}
|
|
301
306
|
}
|
|
@@ -322,7 +327,7 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
322
327
|
headers: {
|
|
323
328
|
'content-type': acceptedMediaType === 'application/json'
|
|
324
329
|
? 'application/json; charset=utf-8'
|
|
325
|
-
: 'application/graphql+json; charset=utf-8',
|
|
330
|
+
: 'application/graphql-response+json; charset=utf-8',
|
|
326
331
|
},
|
|
327
332
|
},
|
|
328
333
|
];
|
|
@@ -346,7 +351,7 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
346
351
|
})), { headers: {
|
|
347
352
|
'content-type': acceptedMediaType === 'application/json'
|
|
348
353
|
? 'application/json; charset=utf-8'
|
|
349
|
-
: 'application/graphql+json; charset=utf-8',
|
|
354
|
+
: 'application/graphql-response+json; charset=utf-8',
|
|
350
355
|
} }),
|
|
351
356
|
];
|
|
352
357
|
}
|
package/lib/handler.mjs
CHANGED
|
@@ -51,7 +51,7 @@ export function isResponse(val) {
|
|
|
51
51
|
* url: req.url,
|
|
52
52
|
* method: req.method,
|
|
53
53
|
* headers: req.headers,
|
|
54
|
-
* body:
|
|
54
|
+
* body: () => new Promise((resolve) => {
|
|
55
55
|
* let body = '';
|
|
56
56
|
* req.on('data', (chunk) => (body += chunk));
|
|
57
57
|
* req.on('end', () => resolve(body));
|
|
@@ -96,7 +96,7 @@ export function createHandler(options) {
|
|
|
96
96
|
status: 406,
|
|
97
97
|
statusText: 'Not Acceptable',
|
|
98
98
|
headers: {
|
|
99
|
-
accept: 'application/graphql+json; charset=utf-8, application/json; charset=utf-8',
|
|
99
|
+
accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
|
|
100
100
|
},
|
|
101
101
|
},
|
|
102
102
|
];
|
|
@@ -138,16 +138,21 @@ export function createHandler(options) {
|
|
|
138
138
|
if (!req.body) {
|
|
139
139
|
throw new Error('Missing body');
|
|
140
140
|
}
|
|
141
|
+
let data;
|
|
141
142
|
try {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
partParams.query = data.query;
|
|
145
|
-
partParams.variables = data.variables;
|
|
146
|
-
partParams.extensions = data.extensions;
|
|
143
|
+
const body = typeof req.body === 'function' ? await req.body() : req.body;
|
|
144
|
+
data = typeof body === 'string' ? JSON.parse(body) : body;
|
|
147
145
|
}
|
|
148
|
-
catch (
|
|
146
|
+
catch (err) {
|
|
149
147
|
throw new Error('Unparsable JSON body');
|
|
150
148
|
}
|
|
149
|
+
if (!isObject(data)) {
|
|
150
|
+
throw new Error('JSON body must be an object');
|
|
151
|
+
}
|
|
152
|
+
partParams.operationName = data.operationName;
|
|
153
|
+
partParams.query = data.query;
|
|
154
|
+
partParams.variables = data.variables;
|
|
155
|
+
partParams.extensions = data.extensions;
|
|
151
156
|
break;
|
|
152
157
|
}
|
|
153
158
|
default: // graphql-http doesnt support any other content type
|
|
@@ -225,7 +230,7 @@ export function createHandler(options) {
|
|
|
225
230
|
throw null;
|
|
226
231
|
operation = ast.operation;
|
|
227
232
|
}
|
|
228
|
-
catch (
|
|
233
|
+
catch (_d) {
|
|
229
234
|
return makeResponse(new GraphQLError('Unable to detect operation AST'), acceptedMediaType);
|
|
230
235
|
}
|
|
231
236
|
if (operation === 'subscription') {
|
|
@@ -286,11 +291,11 @@ export function getAcceptableMediaType(acceptHeader) {
|
|
|
286
291
|
acceptedMediaType = 'application/json';
|
|
287
292
|
break;
|
|
288
293
|
}
|
|
289
|
-
if ((mediaType === 'application/graphql+json' ||
|
|
294
|
+
if ((mediaType === 'application/graphql-response+json' ||
|
|
290
295
|
mediaType === 'application/*' ||
|
|
291
296
|
mediaType === '*/*') &&
|
|
292
297
|
charset === 'charset=utf8') {
|
|
293
|
-
acceptedMediaType = 'application/graphql+json';
|
|
298
|
+
acceptedMediaType = 'application/graphql-response+json';
|
|
294
299
|
break;
|
|
295
300
|
}
|
|
296
301
|
}
|
|
@@ -316,7 +321,7 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
316
321
|
headers: {
|
|
317
322
|
'content-type': acceptedMediaType === 'application/json'
|
|
318
323
|
? 'application/json; charset=utf-8'
|
|
319
|
-
: 'application/graphql+json; charset=utf-8',
|
|
324
|
+
: 'application/graphql-response+json; charset=utf-8',
|
|
320
325
|
},
|
|
321
326
|
},
|
|
322
327
|
];
|
|
@@ -340,7 +345,7 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
340
345
|
})), { headers: {
|
|
341
346
|
'content-type': acceptedMediaType === 'application/json'
|
|
342
347
|
? 'application/json; charset=utf-8'
|
|
343
|
-
: 'application/graphql+json; charset=utf-8',
|
|
348
|
+
: 'application/graphql-response+json; charset=utf-8',
|
|
344
349
|
} }),
|
|
345
350
|
];
|
|
346
351
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/index.mjs
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ExecutionResult, GraphQLError } from 'graphql';
|
|
7
7
|
/** @private */
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function extendedTypeof(val: unknown): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' | 'null';
|
|
9
|
+
/** @private */
|
|
10
|
+
export declare function isObject(val: unknown): val is Record<PropertyKey, any>;
|
|
9
11
|
/** @private */
|
|
10
12
|
export declare function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[];
|
|
11
13
|
/** @private */
|
package/lib/utils.js
CHANGED
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.isAsyncIterable = exports.isExecutionResult = exports.areGraphQLErrors = exports.isObject = void 0;
|
|
8
|
+
exports.isAsyncIterable = exports.isExecutionResult = exports.areGraphQLErrors = exports.isObject = exports.extendedTypeof = void 0;
|
|
9
|
+
/** @private */
|
|
10
|
+
function extendedTypeof(val) {
|
|
11
|
+
if (val === null) {
|
|
12
|
+
return 'null';
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(val)) {
|
|
15
|
+
return 'array';
|
|
16
|
+
}
|
|
17
|
+
return typeof val;
|
|
18
|
+
}
|
|
19
|
+
exports.extendedTypeof = extendedTypeof;
|
|
9
20
|
/** @private */
|
|
10
21
|
function isObject(val) {
|
|
11
22
|
return typeof val === 'object' && val !== null;
|
package/lib/utils.mjs
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
/** @private */
|
|
7
|
+
export function extendedTypeof(val) {
|
|
8
|
+
if (val === null) {
|
|
9
|
+
return 'null';
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(val)) {
|
|
12
|
+
return 'array';
|
|
13
|
+
}
|
|
14
|
+
return typeof val;
|
|
15
|
+
}
|
|
16
|
+
/** @private */
|
|
7
17
|
export function isObject(val) {
|
|
8
18
|
return typeof val === 'object' && val !== null;
|
|
9
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -65,35 +65,35 @@
|
|
|
65
65
|
"graphql": ">=0.11 <=16"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@babel/core": "^7.18.
|
|
68
|
+
"@babel/core": "^7.18.13",
|
|
69
69
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
70
70
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
71
71
|
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
|
|
72
72
|
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
|
|
73
73
|
"@babel/preset-env": "^7.18.10",
|
|
74
74
|
"@babel/preset-typescript": "^7.18.6",
|
|
75
|
-
"@rollup/plugin-typescript": "^8.
|
|
75
|
+
"@rollup/plugin-typescript": "^8.4.0",
|
|
76
76
|
"@semantic-release/changelog": "^6.0.1",
|
|
77
77
|
"@semantic-release/git": "^10.0.1",
|
|
78
|
-
"@types/jest": "^
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
80
|
-
"@typescript-eslint/parser": "^5.
|
|
81
|
-
"babel-jest": "^
|
|
82
|
-
"eslint": "^8.
|
|
78
|
+
"@types/jest": "^29.0.0",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
80
|
+
"@typescript-eslint/parser": "^5.36.1",
|
|
81
|
+
"babel-jest": "^29.0.1",
|
|
82
|
+
"eslint": "^8.23.0",
|
|
83
83
|
"eslint-config-prettier": "^8.5.0",
|
|
84
84
|
"eslint-plugin-prettier": "^4.2.1",
|
|
85
|
-
"graphql": "^16.
|
|
86
|
-
"jest": "^
|
|
87
|
-
"jest-jasmine2": "^
|
|
85
|
+
"graphql": "^16.6.0",
|
|
86
|
+
"jest": "^29.0.1",
|
|
87
|
+
"jest-jasmine2": "^29.0.1",
|
|
88
88
|
"node-fetch": "^3.2.10",
|
|
89
89
|
"prettier": "^2.7.1",
|
|
90
90
|
"replacestream": "^4.0.3",
|
|
91
|
-
"rollup": "^2.
|
|
91
|
+
"rollup": "^2.78.1",
|
|
92
92
|
"rollup-plugin-terser": "^7.0.2",
|
|
93
|
-
"semantic-release": "^19.0.
|
|
93
|
+
"semantic-release": "^19.0.5",
|
|
94
94
|
"tslib": "^2.4.0",
|
|
95
|
-
"typedoc": "^0.23.
|
|
95
|
+
"typedoc": "^0.23.11",
|
|
96
96
|
"typedoc-plugin-markdown": "^3.13.4",
|
|
97
|
-
"typescript": "^4.
|
|
97
|
+
"typescript": "^4.8.2"
|
|
98
98
|
}
|
|
99
99
|
}
|
package/umd/graphql-http.js
CHANGED
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
res = await fetchFn(url, {
|
|
102
102
|
signal: control.signal,
|
|
103
103
|
method: 'POST',
|
|
104
|
-
headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql+json, application/json' }),
|
|
104
|
+
headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql-response+json, application/json' }),
|
|
105
105
|
credentials,
|
|
106
106
|
referrer,
|
|
107
107
|
referrerPolicy,
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
const contentType = res.headers.get('content-type');
|
|
119
119
|
if (!contentType)
|
|
120
120
|
throw new Error('Missing response content-type');
|
|
121
|
-
if (!contentType.includes('application/graphql+json') &&
|
|
121
|
+
if (!contentType.includes('application/graphql-response+json') &&
|
|
122
122
|
!contentType.includes('application/json')) {
|
|
123
123
|
throw new Error(`Unsupported response content-type ${contentType}`);
|
|
124
124
|
}
|
package/umd/graphql-http.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlHttp={})}(this,(function(e){"use strict";class t extends Error{constructor(e){let t,r;var o;(function(e){return"object"==typeof e&&null!==e})(o=e)&&"boolean"==typeof o.ok&&"number"==typeof o.status&&"string"==typeof o.statusText?(r=e,t="Server responded with "+e.status+": "+e.statusText):t=e instanceof Error?e.message:String(e),super(t),this.name=this.constructor.name,this.response=r}}e.NetworkError=t,e.createClient=function(e){const{credentials:r="same-origin",referrer:o,referrerPolicy:n,shouldRetry:s=(()=>!1)}=e,i=e.fetchFn||fetch,a=e.abortControllerImpl||AbortController,c=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:r=>e?(setTimeout((()=>r()),0),()=>{}):(t.push(r),()=>{t.splice(t.indexOf(r),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();return{subscribe(l
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlHttp={})}(this,(function(e){"use strict";class t extends Error{constructor(e){let t,r;var o;(function(e){return"object"==typeof e&&null!==e})(o=e)&&"boolean"==typeof o.ok&&"number"==typeof o.status&&"string"==typeof o.statusText?(r=e,t="Server responded with "+e.status+": "+e.statusText):t=e instanceof Error?e.message:String(e),super(t),this.name=this.constructor.name,this.response=r}}e.NetworkError=t,e.createClient=function(e){const{credentials:r="same-origin",referrer:o,referrerPolicy:n,shouldRetry:s=(()=>!1)}=e,i=e.fetchFn||fetch,a=e.abortControllerImpl||AbortController,c=(()=>{let e=!1;const t=[];return{get disposed(){return e},onDispose:r=>e?(setTimeout((()=>r()),0),()=>{}):(t.push(r),()=>{t.splice(t.indexOf(r),1)}),dispose(){if(!e){e=!0;for(const e of[...t])e()}}}})();return{subscribe(p,l){if(c.disposed)throw new Error("Client has been disposed");const f=new a,u=c.onDispose((()=>{u(),f.abort()}));return(async()=>{var a;let c=null,u=0;for(;;){if(c){const e=await s(c,u);if(f.signal.aborted)return;if(!e)throw c;u++}try{const s="function"==typeof e.url?await e.url(p):e.url;if(f.signal.aborted)return;const c="function"==typeof e.headers?await e.headers():null!==(a=e.headers)&&void 0!==a?a:{};if(f.signal.aborted)return;let u;try{u=await i(s,{signal:f.signal,method:"POST",headers:Object.assign(Object.assign({},c),{"content-type":"application/json; charset=utf-8",accept:"application/graphql-response+json, application/json"}),credentials:r,referrer:o,referrerPolicy:n,body:JSON.stringify(p)})}catch(e){throw new t(e)}if(!u.ok)throw new t(u);if(!u.body)throw new Error("Missing response body");const d=u.headers.get("content-type");if(!d)throw new Error("Missing response content-type");if(!d.includes("application/graphql-response+json")&&!d.includes("application/json"))throw new Error(`Unsupported response content-type ${d}`);const h=await u.json();return l.next(h),f.abort()}catch(e){if(f.signal.aborted)return;if(!(e instanceof t))throw e;c=e}}})().then((()=>l.complete())).catch((e=>l.error(e))),()=>f.abort()},dispose(){c.dispose()}}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
Binary file
|