graphql-http 1.4.0 → 1.6.1
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 +55 -21
- package/lib/audits/common.d.mts +58 -0
- 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.mts +2 -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.mts +39 -0
- package/lib/audits/server.d.ts +39 -0
- package/lib/audits/server.js +642 -0
- package/lib/audits/server.mjs +637 -0
- package/lib/audits/utils.d.mts +38 -0
- package/lib/audits/utils.d.ts +38 -0
- package/lib/audits/utils.js +132 -0
- package/lib/audits/utils.mjs +112 -0
- package/lib/client.d.mts +155 -0
- package/lib/common.d.mts +31 -0
- package/lib/handler.d.mts +285 -0
- package/lib/handler.d.ts +1 -1
- package/lib/handler.js +1 -1
- package/lib/handler.mjs +2 -2
- package/lib/index.d.mts +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/lib/utils.d.mts +16 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +12 -1
- package/lib/utils.mjs +10 -0
- package/package.json +24 -19
- package/umd/graphql-http.min.js.gz +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* audit/utils
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
import { ExecutionResult } from 'graphql';
|
|
7
|
+
import { Audit, AuditName } from './common';
|
|
8
|
+
export * from '../utils';
|
|
9
|
+
/**
|
|
10
|
+
* Wrap and prepare an audit for testing.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export declare function audit(name: AuditName, fn: () => Promise<void>): Audit;
|
|
15
|
+
/**
|
|
16
|
+
* Will throw a string if the assertion fails.
|
|
17
|
+
*
|
|
18
|
+
* All fatal problems will throw an instance of Error.
|
|
19
|
+
*
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
export declare function assert<T = unknown>(name: string, actual: T): {
|
|
23
|
+
toBe: (expected: T) => void;
|
|
24
|
+
toBeLessThanOrEqual: (expected: T extends number ? T : never) => void;
|
|
25
|
+
toBeGreaterThanOrEqual: (expected: T extends number ? T : never) => void;
|
|
26
|
+
toContain: (expected: T extends (infer U)[] ? U : T extends string ? T : never) => void;
|
|
27
|
+
notToContain: (expected: T extends (infer U_1)[] ? U_1 : T extends string ? T : never) => void;
|
|
28
|
+
toHaveProperty: (prop: T extends Record<any, any> ? PropertyKey : never) => void;
|
|
29
|
+
notToHaveProperty: (prop: T extends Record<any, any> ? PropertyKey : never) => void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Parses the string as JSON and safely reports parsing issues for audits.
|
|
33
|
+
*
|
|
34
|
+
* Assumes the parsed JSON will be an `ExecutionResult`.
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* */
|
|
38
|
+
export declare function assertBodyAsExecutionResult(res: Response): Promise<ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* audit/utils
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.assertBodyAsExecutionResult = exports.assert = exports.audit = void 0;
|
|
23
|
+
__exportStar(require("../utils"), exports);
|
|
24
|
+
/**
|
|
25
|
+
* Wrap and prepare an audit for testing.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
function audit(name, fn) {
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
fn: async () => {
|
|
33
|
+
try {
|
|
34
|
+
await fn();
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
status: 'ok',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (errOrReason) {
|
|
41
|
+
if (typeof errOrReason !== 'string') {
|
|
42
|
+
// anything thrown that is not an assertion string is considered fatal
|
|
43
|
+
throw errOrReason;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
status: name.startsWith('MUST')
|
|
48
|
+
? // only failing MUSTs are considered errors
|
|
49
|
+
'error'
|
|
50
|
+
: // everything else is optional and considered a warning
|
|
51
|
+
'warn',
|
|
52
|
+
reason: errOrReason,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.audit = audit;
|
|
59
|
+
/**
|
|
60
|
+
* Will throw a string if the assertion fails.
|
|
61
|
+
*
|
|
62
|
+
* All fatal problems will throw an instance of Error.
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
function assert(name, actual) {
|
|
67
|
+
return {
|
|
68
|
+
toBe: (expected) => {
|
|
69
|
+
if (actual !== expected) {
|
|
70
|
+
throw `${name} ${actual} is not ${expected}`;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
toBeLessThanOrEqual: (expected) => {
|
|
74
|
+
if (!(actual <= expected)) {
|
|
75
|
+
throw `${name} ${actual} is not less than or equal to ${expected}`;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
toBeGreaterThanOrEqual: (expected) => {
|
|
79
|
+
if (!(actual >= expected)) {
|
|
80
|
+
throw `${name} ${actual} is not greater than or equal to ${expected}`;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
toContain: (expected) => {
|
|
84
|
+
// @ts-expect-error types will match, otherwise never
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
if (!actual.includes(expected)) {
|
|
87
|
+
throw `${name} ${JSON.stringify(actual)} does not contain ${JSON.stringify(expected)}`;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
notToContain: (expected) => {
|
|
91
|
+
// @ts-expect-error types will match, otherwise never
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
if (actual.includes(expected)) {
|
|
94
|
+
throw `${name} ${JSON.stringify(actual)} contains ${JSON.stringify(expected)}`;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
toHaveProperty: (
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
prop) => {
|
|
100
|
+
// @ts-expect-error types will match, otherwise never
|
|
101
|
+
if (!(prop in actual)) {
|
|
102
|
+
throw `${name} ${JSON.stringify(actual)} does not have a property '${String(prop)}'`;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
notToHaveProperty: (
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
prop) => {
|
|
108
|
+
// @ts-expect-error types will match, otherwise never
|
|
109
|
+
if (prop in actual) {
|
|
110
|
+
throw `${name} ${JSON.stringify(actual)} does have a property '${String(prop)}'`;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.assert = assert;
|
|
116
|
+
/**
|
|
117
|
+
* Parses the string as JSON and safely reports parsing issues for audits.
|
|
118
|
+
*
|
|
119
|
+
* Assumes the parsed JSON will be an `ExecutionResult`.
|
|
120
|
+
*
|
|
121
|
+
* @private
|
|
122
|
+
* */
|
|
123
|
+
async function assertBodyAsExecutionResult(res) {
|
|
124
|
+
const str = await res.text();
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(str);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
throw `Response body is not valid JSON. Got ${JSON.stringify(str)}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.assertBodyAsExecutionResult = assertBodyAsExecutionResult;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* audit/utils
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export * from '../utils.mjs';
|
|
7
|
+
/**
|
|
8
|
+
* Wrap and prepare an audit for testing.
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function audit(name, fn) {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
fn: async () => {
|
|
16
|
+
try {
|
|
17
|
+
await fn();
|
|
18
|
+
return {
|
|
19
|
+
name,
|
|
20
|
+
status: 'ok',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (errOrReason) {
|
|
24
|
+
if (typeof errOrReason !== 'string') {
|
|
25
|
+
// anything thrown that is not an assertion string is considered fatal
|
|
26
|
+
throw errOrReason;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name,
|
|
30
|
+
status: name.startsWith('MUST')
|
|
31
|
+
? // only failing MUSTs are considered errors
|
|
32
|
+
'error'
|
|
33
|
+
: // everything else is optional and considered a warning
|
|
34
|
+
'warn',
|
|
35
|
+
reason: errOrReason,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Will throw a string if the assertion fails.
|
|
43
|
+
*
|
|
44
|
+
* All fatal problems will throw an instance of Error.
|
|
45
|
+
*
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
export function assert(name, actual) {
|
|
49
|
+
return {
|
|
50
|
+
toBe: (expected) => {
|
|
51
|
+
if (actual !== expected) {
|
|
52
|
+
throw `${name} ${actual} is not ${expected}`;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
toBeLessThanOrEqual: (expected) => {
|
|
56
|
+
if (!(actual <= expected)) {
|
|
57
|
+
throw `${name} ${actual} is not less than or equal to ${expected}`;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
toBeGreaterThanOrEqual: (expected) => {
|
|
61
|
+
if (!(actual >= expected)) {
|
|
62
|
+
throw `${name} ${actual} is not greater than or equal to ${expected}`;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
toContain: (expected) => {
|
|
66
|
+
// @ts-expect-error types will match, otherwise never
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
if (!actual.includes(expected)) {
|
|
69
|
+
throw `${name} ${JSON.stringify(actual)} does not contain ${JSON.stringify(expected)}`;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
notToContain: (expected) => {
|
|
73
|
+
// @ts-expect-error types will match, otherwise never
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
if (actual.includes(expected)) {
|
|
76
|
+
throw `${name} ${JSON.stringify(actual)} contains ${JSON.stringify(expected)}`;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
toHaveProperty: (
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
prop) => {
|
|
82
|
+
// @ts-expect-error types will match, otherwise never
|
|
83
|
+
if (!(prop in actual)) {
|
|
84
|
+
throw `${name} ${JSON.stringify(actual)} does not have a property '${String(prop)}'`;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
notToHaveProperty: (
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
prop) => {
|
|
90
|
+
// @ts-expect-error types will match, otherwise never
|
|
91
|
+
if (prop in actual) {
|
|
92
|
+
throw `${name} ${JSON.stringify(actual)} does have a property '${String(prop)}'`;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parses the string as JSON and safely reports parsing issues for audits.
|
|
99
|
+
*
|
|
100
|
+
* Assumes the parsed JSON will be an `ExecutionResult`.
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
* */
|
|
104
|
+
export async function assertBodyAsExecutionResult(res) {
|
|
105
|
+
const str = await res.text();
|
|
106
|
+
try {
|
|
107
|
+
return JSON.parse(str);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
throw `Response body is not valid JSON. Got ${JSON.stringify(str)}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/lib/client.d.mts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* client
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
import type { ExecutionResult } from 'graphql';
|
|
7
|
+
import { RequestParams, Sink } from './common';
|
|
8
|
+
/** This file is the entry point for browsers, re-export common elements. */
|
|
9
|
+
export * from './common';
|
|
10
|
+
/** @category Client */
|
|
11
|
+
export interface ClientOptions {
|
|
12
|
+
/**
|
|
13
|
+
* URL of the GraphQL over HTTP server to connect.
|
|
14
|
+
*
|
|
15
|
+
* If the option is a function, it will be called on each request.
|
|
16
|
+
* Returning a Promise is supported too and the request will stall until it
|
|
17
|
+
* resolves.
|
|
18
|
+
*
|
|
19
|
+
* A good use-case for having a function is when using the URL for authentication,
|
|
20
|
+
* where subsequent requests (due to auth) may have a refreshed identity token.
|
|
21
|
+
*
|
|
22
|
+
* Function receives the request params. Useful for example, to ease up debugging and DevTools
|
|
23
|
+
* navigation you might want to use the operation name in the URL's search params (`/graphql?MyQuery`).
|
|
24
|
+
*/
|
|
25
|
+
url: string | ((request: RequestParams) => Promise<string> | string);
|
|
26
|
+
/**
|
|
27
|
+
* Indicates whether the user agent should send cookies from the other domain in the case
|
|
28
|
+
* of cross-origin requests.
|
|
29
|
+
*
|
|
30
|
+
* Possible options are:
|
|
31
|
+
* - `omit`: Never send or receive cookies.
|
|
32
|
+
* - `same-origin`: Send user credentials (cookies, basic http auth, etc..) if the URL is on the same origin as the calling script.
|
|
33
|
+
* - `include`: Always send user credentials (cookies, basic http auth, etc..), even for cross-origin calls.
|
|
34
|
+
*
|
|
35
|
+
* @default same-origin
|
|
36
|
+
*/
|
|
37
|
+
credentials?: 'omit' | 'same-origin' | 'include';
|
|
38
|
+
/**
|
|
39
|
+
* A string specifying the referrer of the request. This can be a same-origin URL, about:client, or an empty string.
|
|
40
|
+
*
|
|
41
|
+
* @default undefined
|
|
42
|
+
*/
|
|
43
|
+
referrer?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Specifies the referrer policy to use for the request.
|
|
46
|
+
*
|
|
47
|
+
* Possible options are:
|
|
48
|
+
* - `no-referrer`: Does not send referrer information along with requests to any origin.
|
|
49
|
+
* - `no-referrer-when-downgrade`: Sends full referrerURL for requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL.
|
|
50
|
+
* - `same-origin`: Sends full referrerURL as referrer information when making same-origin-referrer requests.
|
|
51
|
+
* - `origin`: Sends only the ASCII serialization of the request’s referrerURL when making both same-origin-referrer requests and cross-origin-referrer requests.
|
|
52
|
+
* - `strict-origin`: Sends the ASCII serialization of the origin of the referrerURL for requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL
|
|
53
|
+
* - `origin-when-cross-origin`: Sends full referrerURL when making same-origin-referrer requests, and only the ASCII serialization of the origin of the request’s referrerURL is sent when making cross-origin-referrer requests
|
|
54
|
+
* - `strict-origin-when-cross-origin`: Sends full referrerURL when making same-origin-referrer requests, and only the ASCII serialization of the origin of the request’s referrerURL when making cross-origin-referrer requests: whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL.
|
|
55
|
+
* - `unsafe-url`: Sends full referrerURL along for both same-origin-referrer requests and cross-origin-referrer requests.
|
|
56
|
+
*
|
|
57
|
+
* @default undefined
|
|
58
|
+
*/
|
|
59
|
+
referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
|
|
60
|
+
/**
|
|
61
|
+
* HTTP headers to pass along the request.
|
|
62
|
+
*
|
|
63
|
+
* If the option is a function, it will be called on each request.
|
|
64
|
+
* Returning a Promise is supported too and the request will stall until it
|
|
65
|
+
* resolves.
|
|
66
|
+
*
|
|
67
|
+
* A good use-case for having a function is when using the URL for authentication,
|
|
68
|
+
* where subsequent requests (due to auth) may have a refreshed identity token.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Record<string, string> | (() => Promise<Record<string, string> | null | void> | Record<string, string> | null | void);
|
|
71
|
+
/**
|
|
72
|
+
* Control whether the network request error should be retried.
|
|
73
|
+
*
|
|
74
|
+
* Please note that you can **only** control network errors, all other
|
|
75
|
+
* errors are considered fatal and will be reported immediately.
|
|
76
|
+
*
|
|
77
|
+
* You may implement your own waiting strategy by timing the resolution of the returned promise.
|
|
78
|
+
*
|
|
79
|
+
* Useful for retrying requests that failed because the service is temporarely unavailable.
|
|
80
|
+
*
|
|
81
|
+
* `retries` argument counts actual retries, so it will begin with
|
|
82
|
+
* 0 after the first failed request.
|
|
83
|
+
*
|
|
84
|
+
* Returning `false` will report the `err` argument; however, throwing a different error from
|
|
85
|
+
* the `err` argument, will report it instead.
|
|
86
|
+
*
|
|
87
|
+
* @default '() => false'
|
|
88
|
+
*/
|
|
89
|
+
shouldRetry?: (err: NetworkError, retries: number) => Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* The Fetch function to use.
|
|
92
|
+
*
|
|
93
|
+
* For NodeJS environments consider using [`node-fetch`](https://github.com/node-fetch/node-fetch).
|
|
94
|
+
*
|
|
95
|
+
* @default global.fetch
|
|
96
|
+
*/
|
|
97
|
+
fetchFn?: unknown;
|
|
98
|
+
/**
|
|
99
|
+
* The AbortController implementation to use.
|
|
100
|
+
*
|
|
101
|
+
* For NodeJS environments before v15 consider using [`node-abort-controller`](https://github.com/southpolesteve/node-abort-controller).
|
|
102
|
+
*
|
|
103
|
+
* @default global.AbortController
|
|
104
|
+
*/
|
|
105
|
+
abortControllerImpl?: unknown;
|
|
106
|
+
}
|
|
107
|
+
/** @category Client */
|
|
108
|
+
export interface Client {
|
|
109
|
+
/**
|
|
110
|
+
* Subscribes to receive a response by making an HTTP request.
|
|
111
|
+
*
|
|
112
|
+
* It uses the `sink` to emit the received data or errors. Returns a _dispose_
|
|
113
|
+
* function used for canceling active requests and cleaning up.
|
|
114
|
+
*/
|
|
115
|
+
subscribe<Data = Record<string, unknown>, Extensions = unknown>(request: RequestParams, sink: Sink<ExecutionResult<Data, Extensions>>): () => void;
|
|
116
|
+
/**
|
|
117
|
+
* Dispose of the client, cancel all active requests and clean up resources.
|
|
118
|
+
*/
|
|
119
|
+
dispose: () => void;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Creates a disposable GraphQL over HTTP client to transmit
|
|
123
|
+
* GraphQL operation results.
|
|
124
|
+
*
|
|
125
|
+
* @category Client
|
|
126
|
+
*/
|
|
127
|
+
export declare function createClient(options: ClientOptions): Client;
|
|
128
|
+
/**
|
|
129
|
+
* A network error caused by the client or an unexpected response from the server.
|
|
130
|
+
*
|
|
131
|
+
* To avoid bundling DOM typings (because the client can run in Node env too),
|
|
132
|
+
* you should supply the `Response` generic depending on your Fetch implementation.
|
|
133
|
+
*
|
|
134
|
+
* @category Client
|
|
135
|
+
*/
|
|
136
|
+
export declare class NetworkError<Response extends ResponseLike = ResponseLike> extends Error {
|
|
137
|
+
/**
|
|
138
|
+
* The underlyig response thats considered an error.
|
|
139
|
+
*
|
|
140
|
+
* Will be undefined when no response is received,
|
|
141
|
+
* instead an unexpected network error.
|
|
142
|
+
*/
|
|
143
|
+
response: Response | undefined;
|
|
144
|
+
constructor(msgOrErrOrResponse: string | Error | Response);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Concrete interface a response needs to implement for the client.
|
|
148
|
+
*
|
|
149
|
+
* @category Client
|
|
150
|
+
*/
|
|
151
|
+
export interface ResponseLike {
|
|
152
|
+
readonly ok: boolean;
|
|
153
|
+
readonly status: number;
|
|
154
|
+
readonly statusText: string;
|
|
155
|
+
}
|
package/lib/common.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* common
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for GraphQL's request for execution.
|
|
8
|
+
*
|
|
9
|
+
* Reference: https://graphql.github.io/graphql-over-http/draft/#sec-Request-Parameters
|
|
10
|
+
*
|
|
11
|
+
* @category Common
|
|
12
|
+
*/
|
|
13
|
+
export interface RequestParams {
|
|
14
|
+
operationName?: string | undefined;
|
|
15
|
+
query: string;
|
|
16
|
+
variables?: Record<string, unknown> | undefined;
|
|
17
|
+
extensions?: Record<string, unknown> | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A representation of any set of values over any amount of time.
|
|
21
|
+
*
|
|
22
|
+
* @category Common
|
|
23
|
+
*/
|
|
24
|
+
export interface Sink<T = unknown> {
|
|
25
|
+
/** Next value arriving. */
|
|
26
|
+
next(value: T): void;
|
|
27
|
+
/** An error that has occured. This function "closes" the sink. */
|
|
28
|
+
error(error: unknown): void;
|
|
29
|
+
/** The sink has completed. This function "closes" the sink. */
|
|
30
|
+
complete(): void;
|
|
31
|
+
}
|