graphql-http 1.0.0 → 1.3.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 +53 -1
- package/lib/client.d.ts +11 -3
- package/lib/client.js +3 -3
- package/lib/client.mjs +3 -3
- package/lib/common.d.ts +0 -67
- package/lib/common.js +0 -12
- package/lib/common.mjs +1 -10
- package/lib/handler.d.ts +133 -9
- package/lib/handler.js +136 -97
- package/lib/handler.mjs +129 -93
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +21 -1
- package/lib/utils.mjs +17 -0
- package/package.json +7 -7
- package/umd/graphql-http.js +3 -19
- package/umd/graphql-http.min.js +1 -1
- package/umd/graphql-http.min.js.gz +0 -0
package/lib/utils.js
CHANGED
|
@@ -5,9 +5,29 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.isObject = void 0;
|
|
8
|
+
exports.isAsyncIterable = exports.isExecutionResult = exports.areGraphQLErrors = exports.isObject = void 0;
|
|
9
9
|
/** @private */
|
|
10
10
|
function isObject(val) {
|
|
11
11
|
return typeof val === 'object' && val !== null;
|
|
12
12
|
}
|
|
13
13
|
exports.isObject = isObject;
|
|
14
|
+
/** @private */
|
|
15
|
+
function areGraphQLErrors(obj) {
|
|
16
|
+
return (Array.isArray(obj) &&
|
|
17
|
+
// must be at least one error
|
|
18
|
+
obj.length > 0 &&
|
|
19
|
+
// error has at least a message
|
|
20
|
+
obj.every((ob) => 'message' in ob));
|
|
21
|
+
}
|
|
22
|
+
exports.areGraphQLErrors = areGraphQLErrors;
|
|
23
|
+
/** @private */
|
|
24
|
+
function isExecutionResult(val) {
|
|
25
|
+
return (isObject(val) &&
|
|
26
|
+
('data' in val || ('data' in val && val.data == null && 'errors' in val)));
|
|
27
|
+
}
|
|
28
|
+
exports.isExecutionResult = isExecutionResult;
|
|
29
|
+
/** @private */
|
|
30
|
+
function isAsyncIterable(val) {
|
|
31
|
+
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
32
|
+
}
|
|
33
|
+
exports.isAsyncIterable = isAsyncIterable;
|
package/lib/utils.mjs
CHANGED
|
@@ -7,3 +7,20 @@
|
|
|
7
7
|
export function isObject(val) {
|
|
8
8
|
return typeof val === 'object' && val !== null;
|
|
9
9
|
}
|
|
10
|
+
/** @private */
|
|
11
|
+
export function areGraphQLErrors(obj) {
|
|
12
|
+
return (Array.isArray(obj) &&
|
|
13
|
+
// must be at least one error
|
|
14
|
+
obj.length > 0 &&
|
|
15
|
+
// error has at least a message
|
|
16
|
+
obj.every((ob) => 'message' in ob));
|
|
17
|
+
}
|
|
18
|
+
/** @private */
|
|
19
|
+
export function isExecutionResult(val) {
|
|
20
|
+
return (isObject(val) &&
|
|
21
|
+
('data' in val || ('data' in val && val.data == null && 'errors' in val)));
|
|
22
|
+
}
|
|
23
|
+
/** @private */
|
|
24
|
+
export function isAsyncIterable(val) {
|
|
25
|
+
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Simple,
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"client",
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
"@rollup/plugin-typescript": "^8.3.4",
|
|
76
76
|
"@semantic-release/changelog": "^6.0.1",
|
|
77
77
|
"@semantic-release/git": "^10.0.1",
|
|
78
|
-
"@types/jest": "^28.1.
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
80
|
-
"@typescript-eslint/parser": "^5.
|
|
78
|
+
"@types/jest": "^28.1.7",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
80
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
81
81
|
"babel-jest": "^28.1.3",
|
|
82
|
-
"eslint": "^8.
|
|
82
|
+
"eslint": "^8.22.0",
|
|
83
83
|
"eslint-config-prettier": "^8.5.0",
|
|
84
84
|
"eslint-plugin-prettier": "^4.2.1",
|
|
85
85
|
"graphql": "^16.5.0",
|
|
@@ -88,7 +88,7 @@
|
|
|
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.0",
|
|
92
92
|
"rollup-plugin-terser": "^7.0.2",
|
|
93
93
|
"semantic-release": "^19.0.3",
|
|
94
94
|
"tslib": "^2.4.0",
|
package/umd/graphql-http.js
CHANGED
|
@@ -14,21 +14,6 @@
|
|
|
14
14
|
return typeof val === 'object' && val !== null;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* common
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Checks whether the passed value is the `graphql-http` server agnostic response.
|
|
24
|
-
*
|
|
25
|
-
* @category Common
|
|
26
|
-
*/
|
|
27
|
-
function isResponse(val) {
|
|
28
|
-
// TODO: make sure the contents of init match ResponseInit
|
|
29
|
-
return Array.isArray(val) && typeof val[0] === 'string' && isObject(val[1]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
17
|
/**
|
|
33
18
|
*
|
|
34
19
|
* client
|
|
@@ -102,7 +87,7 @@
|
|
|
102
87
|
}
|
|
103
88
|
try {
|
|
104
89
|
const url = typeof options.url === 'function'
|
|
105
|
-
? await options.url()
|
|
90
|
+
? await options.url(request)
|
|
106
91
|
: options.url;
|
|
107
92
|
if (control.signal.aborted)
|
|
108
93
|
return;
|
|
@@ -116,7 +101,7 @@
|
|
|
116
101
|
res = await fetchFn(url, {
|
|
117
102
|
signal: control.signal,
|
|
118
103
|
method: 'POST',
|
|
119
|
-
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' }),
|
|
120
105
|
credentials,
|
|
121
106
|
referrer,
|
|
122
107
|
referrerPolicy,
|
|
@@ -133,7 +118,7 @@
|
|
|
133
118
|
const contentType = res.headers.get('content-type');
|
|
134
119
|
if (!contentType)
|
|
135
120
|
throw new Error('Missing response content-type');
|
|
136
|
-
if (!contentType.includes('application/graphql+json') &&
|
|
121
|
+
if (!contentType.includes('application/graphql-response+json') &&
|
|
137
122
|
!contentType.includes('application/json')) {
|
|
138
123
|
throw new Error(`Unsupported response content-type ${contentType}`);
|
|
139
124
|
}
|
|
@@ -199,7 +184,6 @@
|
|
|
199
184
|
|
|
200
185
|
exports.NetworkError = NetworkError;
|
|
201
186
|
exports.createClient = createClient;
|
|
202
|
-
exports.isResponse = isResponse;
|
|
203
187
|
|
|
204
188
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
205
189
|
|
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";
|
|
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
|