graphql-http 1.6.1 → 1.7.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.
@@ -0,0 +1,40 @@
1
+ import { HandlerOptions, OperationContext } from '../handler';
2
+ /**
3
+ * The necessary API from the fetch environment for the handler.
4
+ *
5
+ * @category Server/fetch
6
+ */
7
+ export interface FetchAPI {
8
+ Response: typeof Response;
9
+ ReadableStream: typeof ReadableStream;
10
+ TextEncoder: typeof TextEncoder;
11
+ }
12
+ /**
13
+ * Create a GraphQL over HTTP Protocol compliant request handler for
14
+ * a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
15
+ *
16
+ * You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
17
+ * isomorphically use it in _any_ environment. See an example:
18
+ *
19
+ * ```js
20
+ * import http from 'http';
21
+ * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
22
+ * import { createHandler } from 'graphql-http/lib/use/fetch';
23
+ * import { schema } from './my-graphql-step';
24
+ *
25
+ * // Use this adapter in _any_ environment.
26
+ * const adapter = createServerAdapter({
27
+ * handleRequest: createHandler({ schema }),
28
+ * });
29
+ *
30
+ * const server = http.createServer(adapter);
31
+ *
32
+ * server.listen(4000);
33
+ * console.log('Listening to port 4000');
34
+ * ```
35
+ *
36
+ * @param fetchApi - Custom fetch API engine, will use from global scope if left undefined.
37
+ *
38
+ * @category Server/fetch
39
+ */
40
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Request, FetchAPI, Context>, fetchApi?: Partial<FetchAPI>): (req: Request) => Promise<Response>;
@@ -0,0 +1,40 @@
1
+ import { HandlerOptions, OperationContext } from '../handler';
2
+ /**
3
+ * The necessary API from the fetch environment for the handler.
4
+ *
5
+ * @category Server/fetch
6
+ */
7
+ export interface FetchAPI {
8
+ Response: typeof Response;
9
+ ReadableStream: typeof ReadableStream;
10
+ TextEncoder: typeof TextEncoder;
11
+ }
12
+ /**
13
+ * Create a GraphQL over HTTP Protocol compliant request handler for
14
+ * a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
15
+ *
16
+ * You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
17
+ * isomorphically use it in _any_ environment. See an example:
18
+ *
19
+ * ```js
20
+ * import http from 'http';
21
+ * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
22
+ * import { createHandler } from 'graphql-http/lib/use/fetch';
23
+ * import { schema } from './my-graphql-step';
24
+ *
25
+ * // Use this adapter in _any_ environment.
26
+ * const adapter = createServerAdapter({
27
+ * handleRequest: createHandler({ schema }),
28
+ * });
29
+ *
30
+ * const server = http.createServer(adapter);
31
+ *
32
+ * server.listen(4000);
33
+ * console.log('Listening to port 4000');
34
+ * ```
35
+ *
36
+ * @param fetchApi - Custom fetch API engine, will use from global scope if left undefined.
37
+ *
38
+ * @category Server/fetch
39
+ */
40
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Request, FetchAPI, Context>, fetchApi?: Partial<FetchAPI>): (req: Request) => Promise<Response>;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHandler = void 0;
4
+ const handler_1 = require("../handler");
5
+ /**
6
+ * Create a GraphQL over HTTP Protocol compliant request handler for
7
+ * a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
8
+ *
9
+ * You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
10
+ * isomorphically use it in _any_ environment. See an example:
11
+ *
12
+ * ```js
13
+ * import http from 'http';
14
+ * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
15
+ * import { createHandler } from 'graphql-http/lib/use/fetch';
16
+ * import { schema } from './my-graphql-step';
17
+ *
18
+ * // Use this adapter in _any_ environment.
19
+ * const adapter = createServerAdapter({
20
+ * handleRequest: createHandler({ schema }),
21
+ * });
22
+ *
23
+ * const server = http.createServer(adapter);
24
+ *
25
+ * server.listen(4000);
26
+ * console.log('Listening to port 4000');
27
+ * ```
28
+ *
29
+ * @param fetchApi - Custom fetch API engine, will use from global scope if left undefined.
30
+ *
31
+ * @category Server/fetch
32
+ */
33
+ function createHandler(options, fetchApi = {}) {
34
+ const isProd = process.env.NODE_ENV === 'production';
35
+ const api = {
36
+ Response: fetchApi.Response || Response,
37
+ TextEncoder: fetchApi.TextEncoder || TextEncoder,
38
+ ReadableStream: fetchApi.ReadableStream || ReadableStream,
39
+ };
40
+ const handler = (0, handler_1.createHandler)(options);
41
+ return async function handleRequest(req) {
42
+ try {
43
+ const [body, init] = await handler({
44
+ method: req.method,
45
+ url: req.url,
46
+ headers: req.headers,
47
+ body: () => req.text(),
48
+ raw: req,
49
+ context: api,
50
+ });
51
+ return new api.Response(body, init);
52
+ }
53
+ catch (err) {
54
+ // The handler shouldnt throw errors.
55
+ // If you wish to handle them differently, consider implementing your own request handler.
56
+ console.error('Internal error occurred during request handling. ' +
57
+ 'Please check your implementation.', err);
58
+ if (isProd) {
59
+ return new api.Response(null, { status: 500 });
60
+ }
61
+ else {
62
+ return new api.Response(JSON.stringify({
63
+ errors: [
64
+ err instanceof Error
65
+ ? {
66
+ message: err.message,
67
+ stack: err.stack,
68
+ }
69
+ : err,
70
+ ],
71
+ }), {
72
+ status: 500,
73
+ headers: {
74
+ 'content-type': 'application/json; charset=utf-8',
75
+ },
76
+ });
77
+ }
78
+ }
79
+ };
80
+ }
81
+ exports.createHandler = createHandler;
@@ -0,0 +1,77 @@
1
+ import { createHandler as createRawHandler, } from '../handler.mjs';
2
+ /**
3
+ * Create a GraphQL over HTTP Protocol compliant request handler for
4
+ * a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
5
+ *
6
+ * You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
7
+ * isomorphically use it in _any_ environment. See an example:
8
+ *
9
+ * ```js
10
+ * import http from 'http';
11
+ * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
12
+ * import { createHandler } from 'graphql-http/lib/use/fetch';
13
+ * import { schema } from './my-graphql-step/index.mjs';
14
+ *
15
+ * // Use this adapter in _any_ environment.
16
+ * const adapter = createServerAdapter({
17
+ * handleRequest: createHandler({ schema }),
18
+ * });
19
+ *
20
+ * const server = http.createServer(adapter);
21
+ *
22
+ * server.listen(4000);
23
+ * console.log('Listening to port 4000');
24
+ * ```
25
+ *
26
+ * @param fetchApi - Custom fetch API engine, will use from global scope if left undefined.
27
+ *
28
+ * @category Server/fetch
29
+ */
30
+ export function createHandler(options, fetchApi = {}) {
31
+ const isProd = process.env.NODE_ENV === 'production';
32
+ const api = {
33
+ Response: fetchApi.Response || Response,
34
+ TextEncoder: fetchApi.TextEncoder || TextEncoder,
35
+ ReadableStream: fetchApi.ReadableStream || ReadableStream,
36
+ };
37
+ const handler = createRawHandler(options);
38
+ return async function handleRequest(req) {
39
+ try {
40
+ const [body, init] = await handler({
41
+ method: req.method,
42
+ url: req.url,
43
+ headers: req.headers,
44
+ body: () => req.text(),
45
+ raw: req,
46
+ context: api,
47
+ });
48
+ return new api.Response(body, init);
49
+ }
50
+ catch (err) {
51
+ // The handler shouldnt throw errors.
52
+ // If you wish to handle them differently, consider implementing your own request handler.
53
+ console.error('Internal error occurred during request handling. ' +
54
+ 'Please check your implementation.', err);
55
+ if (isProd) {
56
+ return new api.Response(null, { status: 500 });
57
+ }
58
+ else {
59
+ return new api.Response(JSON.stringify({
60
+ errors: [
61
+ err instanceof Error
62
+ ? {
63
+ message: err.message,
64
+ stack: err.stack,
65
+ }
66
+ : err,
67
+ ],
68
+ }), {
69
+ status: 500,
70
+ headers: {
71
+ 'content-type': 'application/json; charset=utf-8',
72
+ },
73
+ });
74
+ }
75
+ }
76
+ };
77
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage, RequestListener } from 'http';
3
+ import { HandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * Create a GraphQL over HTTP Protocol compliant request handler for
6
+ * the Node environment.
7
+ *
8
+ * ```js
9
+ * import http from 'http';
10
+ * import { createHandler } from 'graphql-http/lib/use/node';
11
+ * import { schema } from './my-graphql-step';
12
+ *
13
+ * const server = http.createServer(createHandler({ schema }));
14
+ *
15
+ * server.listen(4000);
16
+ * console.log('Listening to port 4000');
17
+ * ```
18
+ *
19
+ * @category Server/node
20
+ */
21
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<IncomingMessage, undefined, Context>): RequestListener;
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage, RequestListener } from 'http';
3
+ import { HandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * Create a GraphQL over HTTP Protocol compliant request handler for
6
+ * the Node environment.
7
+ *
8
+ * ```js
9
+ * import http from 'http';
10
+ * import { createHandler } from 'graphql-http/lib/use/node';
11
+ * import { schema } from './my-graphql-step';
12
+ *
13
+ * const server = http.createServer(createHandler({ schema }));
14
+ *
15
+ * server.listen(4000);
16
+ * console.log('Listening to port 4000');
17
+ * ```
18
+ *
19
+ * @category Server/node
20
+ */
21
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<IncomingMessage, undefined, Context>): RequestListener;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHandler = void 0;
4
+ const handler_1 = require("../handler");
5
+ /**
6
+ * Create a GraphQL over HTTP Protocol compliant request handler for
7
+ * the Node environment.
8
+ *
9
+ * ```js
10
+ * import http from 'http';
11
+ * import { createHandler } from 'graphql-http/lib/use/node';
12
+ * import { schema } from './my-graphql-step';
13
+ *
14
+ * const server = http.createServer(createHandler({ schema }));
15
+ *
16
+ * server.listen(4000);
17
+ * console.log('Listening to port 4000');
18
+ * ```
19
+ *
20
+ * @category Server/node
21
+ */
22
+ function createHandler(options) {
23
+ const isProd = process.env.NODE_ENV === 'production';
24
+ const handle = (0, handler_1.createHandler)(options);
25
+ return async function requestListener(req, res) {
26
+ try {
27
+ if (!req.url) {
28
+ throw new Error('Missing request URL');
29
+ }
30
+ if (!req.method) {
31
+ throw new Error('Missing request method');
32
+ }
33
+ const [body, init] = await handle({
34
+ url: req.url,
35
+ method: req.method,
36
+ headers: req.headers,
37
+ body: () => new Promise((resolve) => {
38
+ let body = '';
39
+ req.on('data', (chunk) => (body += chunk));
40
+ req.on('end', () => resolve(body));
41
+ }),
42
+ raw: req,
43
+ context: undefined,
44
+ });
45
+ res.writeHead(init.status, init.statusText, init.headers).end(body);
46
+ }
47
+ catch (err) {
48
+ // The handler shouldnt throw errors.
49
+ // If you wish to handle them differently, consider implementing your own request handler.
50
+ console.error('Internal error occurred during request handling. ' +
51
+ 'Please check your implementation.', err);
52
+ if (isProd) {
53
+ res.writeHead(500).end();
54
+ }
55
+ else {
56
+ res
57
+ .writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
58
+ .end(JSON.stringify({
59
+ errors: [
60
+ err instanceof Error
61
+ ? {
62
+ message: err.message,
63
+ stack: err.stack,
64
+ }
65
+ : err,
66
+ ],
67
+ }));
68
+ }
69
+ }
70
+ };
71
+ }
72
+ exports.createHandler = createHandler;
@@ -0,0 +1,68 @@
1
+ import { createHandler as createRawHandler, } from '../handler.mjs';
2
+ /**
3
+ * Create a GraphQL over HTTP Protocol compliant request handler for
4
+ * the Node environment.
5
+ *
6
+ * ```js
7
+ * import http from 'http';
8
+ * import { createHandler } from 'graphql-http/lib/use/node';
9
+ * import { schema } from './my-graphql-step/index.mjs';
10
+ *
11
+ * const server = http.createServer(createHandler({ schema }));
12
+ *
13
+ * server.listen(4000);
14
+ * console.log('Listening to port 4000');
15
+ * ```
16
+ *
17
+ * @category Server/node
18
+ */
19
+ export function createHandler(options) {
20
+ const isProd = process.env.NODE_ENV === 'production';
21
+ const handle = createRawHandler(options);
22
+ return async function requestListener(req, res) {
23
+ try {
24
+ if (!req.url) {
25
+ throw new Error('Missing request URL');
26
+ }
27
+ if (!req.method) {
28
+ throw new Error('Missing request method');
29
+ }
30
+ const [body, init] = await handle({
31
+ url: req.url,
32
+ method: req.method,
33
+ headers: req.headers,
34
+ body: () => new Promise((resolve) => {
35
+ let body = '';
36
+ req.on('data', (chunk) => (body += chunk));
37
+ req.on('end', () => resolve(body));
38
+ }),
39
+ raw: req,
40
+ context: undefined,
41
+ });
42
+ res.writeHead(init.status, init.statusText, init.headers).end(body);
43
+ }
44
+ catch (err) {
45
+ // The handler shouldnt throw errors.
46
+ // If you wish to handle them differently, consider implementing your own request handler.
47
+ console.error('Internal error occurred during request handling. ' +
48
+ 'Please check your implementation.', err);
49
+ if (isProd) {
50
+ res.writeHead(500).end();
51
+ }
52
+ else {
53
+ res
54
+ .writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
55
+ .end(JSON.stringify({
56
+ errors: [
57
+ err instanceof Error
58
+ ? {
59
+ message: err.message,
60
+ stack: err.stack,
61
+ }
62
+ : err,
63
+ ],
64
+ }));
65
+ }
66
+ }
67
+ };
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.6.1",
3
+ "version": "1.7.1",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -16,15 +16,15 @@
16
16
  ],
17
17
  "author": "Denis Badurina <badurinadenis@gmail.com>",
18
18
  "license": "MIT",
19
- "homepage": "https://github.com/enisdenjo/graphql-http#readme",
19
+ "homepage": "https://github.com/graphql/graphql-http#readme",
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/enisdenjo/graphql-http.git"
22
+ "url": "https://github.com/graphql/graphql-http.git"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=12"
26
26
  },
27
- "packageManager": "yarn@3.2.3",
27
+ "packageManager": "yarn@3.2.4",
28
28
  "main": "lib/index.js",
29
29
  "module": "lib/index.mjs",
30
30
  "browser": "umd/graphql-http.js",
@@ -35,6 +35,26 @@
35
35
  "types": "./lib/index.d.ts",
36
36
  "browser": "./umd/graphql-http.js"
37
37
  },
38
+ "./lib/use/fetch": {
39
+ "types": "./lib/use/fetch.d.ts",
40
+ "require": "./lib/use/fetch.js",
41
+ "import": "./lib/use/fetch.mjs"
42
+ },
43
+ "./lib/use/node": {
44
+ "types": "./lib/use/node.d.ts",
45
+ "require": "./lib/use/node.js",
46
+ "import": "./lib/use/node.mjs"
47
+ },
48
+ "./lib/use/express": {
49
+ "types": "./lib/use/express.d.ts",
50
+ "require": "./lib/use/express.js",
51
+ "import": "./lib/use/express.mjs"
52
+ },
53
+ "./lib/use/fastify": {
54
+ "types": "./lib/use/fastify.d.ts",
55
+ "require": "./lib/use/fastify.js",
56
+ "import": "./lib/use/fastify.mjs"
57
+ },
38
58
  "./package.json": "./package.json"
39
59
  },
40
60
  "types": "lib/index.d.ts",
@@ -62,41 +82,45 @@
62
82
  "release": "semantic-release"
63
83
  },
64
84
  "workspaces": [
65
- "implementations/*"
85
+ "implementations/**/*"
66
86
  ],
67
87
  "peerDependencies": {
68
88
  "graphql": ">=0.11 <=16"
69
89
  },
70
90
  "devDependencies": {
71
- "@babel/core": "^7.18.13",
91
+ "@babel/core": "^7.20.2",
72
92
  "@babel/plugin-proposal-class-properties": "^7.18.6",
73
93
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
74
- "@babel/plugin-proposal-object-rest-spread": "^7.18.9",
94
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
75
95
  "@babel/plugin-proposal-optional-chaining": "^7.18.9",
76
- "@babel/preset-env": "^7.18.10",
96
+ "@babel/preset-env": "^7.20.2",
77
97
  "@babel/preset-typescript": "^7.18.6",
78
- "@rollup/plugin-typescript": "^8.4.0",
98
+ "@rollup/plugin-typescript": "^9.0.2",
79
99
  "@semantic-release/changelog": "^6.0.1",
80
100
  "@semantic-release/git": "^10.0.1",
81
- "@types/jest": "^29.0.0",
82
- "@typescript-eslint/eslint-plugin": "^5.36.1",
83
- "@typescript-eslint/parser": "^5.36.1",
84
- "babel-jest": "^29.0.1",
85
- "eslint": "^8.23.0",
101
+ "@types/express": "^4.17.14",
102
+ "@types/jest": "^29.2.2",
103
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
104
+ "@typescript-eslint/parser": "^5.42.1",
105
+ "@whatwg-node/fetch": "^0.5.1",
106
+ "babel-jest": "^29.3.0",
107
+ "eslint": "^8.27.0",
86
108
  "eslint-config-prettier": "^8.5.0",
87
109
  "eslint-plugin-prettier": "^4.2.1",
110
+ "express": "^4.18.2",
111
+ "fastify": "^4.9.2",
88
112
  "graphql": "^16.6.0",
89
- "jest": "^29.0.1",
90
- "jest-jasmine2": "^29.0.1",
113
+ "jest": "^29.3.0",
114
+ "jest-jasmine2": "^29.3.0",
91
115
  "node-fetch": "^3.2.10",
92
116
  "prettier": "^2.7.1",
93
- "rollup": "^2.79.0",
117
+ "rollup": "^3.2.5",
94
118
  "rollup-plugin-terser": "^7.0.2",
95
119
  "semantic-release": "^19.0.5",
96
- "tslib": "^2.4.0",
97
- "typedoc": "^0.23.13",
98
- "typedoc-plugin-markdown": "^3.13.5",
99
- "typescript": "^4.8.2"
120
+ "tslib": "^2.4.1",
121
+ "typedoc": "^0.23.20",
122
+ "typedoc-plugin-markdown": "^3.13.6",
123
+ "typescript": "^4.8.4"
100
124
  },
101
125
  "resolutions": {
102
126
  "npm/libnpmversion": "^3.0.6"
@@ -185,6 +185,4 @@
185
185
  exports.NetworkError = NetworkError;
186
186
  exports.createClient = createClient;
187
187
 
188
- Object.defineProperty(exports, '__esModule', { value: true });
189
-
190
188
  }));
@@ -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(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})}));
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()}}}}));
Binary file