graphql-http 1.2.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/lib/client.js CHANGED
@@ -105,7 +105,7 @@ function createClient(options) {
105
105
  res = await fetchFn(url, {
106
106
  signal: control.signal,
107
107
  method: 'POST',
108
- headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql+json, application/json' }),
108
+ headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql-response+json, application/json' }),
109
109
  credentials,
110
110
  referrer,
111
111
  referrerPolicy,
@@ -122,7 +122,7 @@ function createClient(options) {
122
122
  const contentType = res.headers.get('content-type');
123
123
  if (!contentType)
124
124
  throw new Error('Missing response content-type');
125
- if (!contentType.includes('application/graphql+json') &&
125
+ if (!contentType.includes('application/graphql-response+json') &&
126
126
  !contentType.includes('application/json')) {
127
127
  throw new Error(`Unsupported response content-type ${contentType}`);
128
128
  }
package/lib/client.mjs CHANGED
@@ -88,7 +88,7 @@ export function createClient(options) {
88
88
  res = await fetchFn(url, {
89
89
  signal: control.signal,
90
90
  method: 'POST',
91
- headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql+json, application/json' }),
91
+ headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json; charset=utf-8', accept: 'application/graphql-response+json, application/json' }),
92
92
  credentials,
93
93
  referrer,
94
94
  referrerPolicy,
@@ -105,7 +105,7 @@ export function createClient(options) {
105
105
  const contentType = res.headers.get('content-type');
106
106
  if (!contentType)
107
107
  throw new Error('Missing response content-type');
108
- if (!contentType.includes('application/graphql+json') &&
108
+ if (!contentType.includes('application/graphql-response+json') &&
109
109
  !contentType.includes('application/json')) {
110
110
  throw new Error(`Unsupported response content-type ${contentType}`);
111
111
  }
package/lib/handler.d.ts CHANGED
@@ -258,7 +258,7 @@ export declare function createHandler<RawRequest = unknown, Context = unknown>(o
258
258
  *
259
259
  * @category Server
260
260
  */
261
- export declare type AcceptableMediaType = 'application/graphql+json' | 'application/json';
261
+ export declare type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
262
262
  /**
263
263
  * Inspects the request and detects the appropriate/acceptable Media-Type
264
264
  * looking at the `Accept` header while complying with the GraphQL over HTTP Protocol.
package/lib/handler.js CHANGED
@@ -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
  ];
@@ -291,11 +291,11 @@ function getAcceptableMediaType(acceptHeader) {
291
291
  acceptedMediaType = 'application/json';
292
292
  break;
293
293
  }
294
- if ((mediaType === 'application/graphql+json' ||
294
+ if ((mediaType === 'application/graphql-response+json' ||
295
295
  mediaType === 'application/*' ||
296
296
  mediaType === '*/*') &&
297
297
  charset === 'charset=utf8') {
298
- acceptedMediaType = 'application/graphql+json';
298
+ acceptedMediaType = 'application/graphql-response+json';
299
299
  break;
300
300
  }
301
301
  }
@@ -322,7 +322,7 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
322
322
  headers: {
323
323
  'content-type': acceptedMediaType === 'application/json'
324
324
  ? 'application/json; charset=utf-8'
325
- : 'application/graphql+json; charset=utf-8',
325
+ : 'application/graphql-response+json; charset=utf-8',
326
326
  },
327
327
  },
328
328
  ];
@@ -346,7 +346,7 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
346
346
  })), { headers: {
347
347
  'content-type': acceptedMediaType === 'application/json'
348
348
  ? 'application/json; charset=utf-8'
349
- : 'application/graphql+json; charset=utf-8',
349
+ : 'application/graphql-response+json; charset=utf-8',
350
350
  } }),
351
351
  ];
352
352
  }
package/lib/handler.mjs CHANGED
@@ -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
  ];
@@ -286,11 +286,11 @@ export function getAcceptableMediaType(acceptHeader) {
286
286
  acceptedMediaType = 'application/json';
287
287
  break;
288
288
  }
289
- if ((mediaType === 'application/graphql+json' ||
289
+ if ((mediaType === 'application/graphql-response+json' ||
290
290
  mediaType === 'application/*' ||
291
291
  mediaType === '*/*') &&
292
292
  charset === 'charset=utf8') {
293
- acceptedMediaType = 'application/graphql+json';
293
+ acceptedMediaType = 'application/graphql-response+json';
294
294
  break;
295
295
  }
296
296
  }
@@ -316,7 +316,7 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
316
316
  headers: {
317
317
  'content-type': acceptedMediaType === 'application/json'
318
318
  ? 'application/json; charset=utf-8'
319
- : 'application/graphql+json; charset=utf-8',
319
+ : 'application/graphql-response+json; charset=utf-8',
320
320
  },
321
321
  },
322
322
  ];
@@ -340,7 +340,7 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
340
340
  })), { headers: {
341
341
  'content-type': acceptedMediaType === 'application/json'
342
342
  ? 'application/json; charset=utf-8'
343
- : 'application/graphql+json; charset=utf-8',
343
+ : 'application/graphql-response+json; charset=utf-8',
344
344
  } }),
345
345
  ];
346
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -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.6",
79
- "@typescript-eslint/eslint-plugin": "^5.33.0",
80
- "@typescript-eslint/parser": "^5.33.0",
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.21.0",
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.77.3",
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",
@@ -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
  }
@@ -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,p){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(l):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+json, application/json"}),credentials:r,referrer:o,referrerPolicy:n,body:JSON.stringify(l)})}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+json")&&!d.includes("application/json"))throw new Error(`Unsupported response content-type ${d}`);const h=await u.json();return p.next(h),f.abort()}catch(e){if(f.signal.aborted)return;if(!(e instanceof t))throw e;c=e}}})().then((()=>p.complete())).catch((e=>p.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()}}},Object.defineProperty(e,"__esModule",{value:!0})}));
Binary file