graphql-http 1.3.0 → 1.6.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/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: await new Promise((resolve) => {
58
+ * body: () => new Promise((resolve) => {
59
59
  * let body = '';
60
60
  * req.on('data', (chunk) => (body += chunk));
61
61
  * req.on('end', () => resolve(body));
@@ -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 data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;
147
- partParams.operationName = data.operationName;
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 (_d) {
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 (_e) {
237
+ catch (_d) {
233
238
  return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType);
234
239
  }
235
240
  if (operation === 'subscription') {
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: await new Promise((resolve) => {
54
+ * body: () => new Promise((resolve) => {
55
55
  * let body = '';
56
56
  * req.on('data', (chunk) => (body += chunk));
57
57
  * req.on('end', () => resolve(body));
@@ -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 data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;
143
- partParams.operationName = data.operationName;
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 (_d) {
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 (_e) {
233
+ catch (_d) {
229
234
  return makeResponse(new GraphQLError('Unable to detect operation AST'), acceptedMediaType);
230
235
  }
231
236
  if (operation === 'subscription') {
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './common';
2
2
  export * from './handler';
3
3
  export * from './client';
4
+ export * from './audits';
package/lib/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./common"), exports);
18
18
  __exportStar(require("./handler"), exports);
19
19
  __exportStar(require("./client"), exports);
20
+ __exportStar(require("./audits"), exports);
package/lib/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './common.mjs';
2
2
  export * from './handler.mjs';
3
3
  export * from './client.mjs';
4
+ export * from './audits.mjs';
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 isObject(val: unknown): val is Record<PropertyKey, unknown>;
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.0",
3
+ "version": "1.6.0",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -24,7 +24,7 @@
24
24
  "engines": {
25
25
  "node": ">=12"
26
26
  },
27
- "packageManager": "yarn@3.2.2",
27
+ "packageManager": "yarn@3.2.3",
28
28
  "main": "lib/index.js",
29
29
  "module": "lib/index.mjs",
30
30
  "browser": "umd/graphql-http.js",
@@ -65,35 +65,38 @@
65
65
  "graphql": ">=0.11 <=16"
66
66
  },
67
67
  "devDependencies": {
68
- "@babel/core": "^7.18.10",
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.3.4",
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": "^28.1.7",
79
- "@typescript-eslint/eslint-plugin": "^5.33.1",
80
- "@typescript-eslint/parser": "^5.33.1",
81
- "babel-jest": "^28.1.3",
82
- "eslint": "^8.22.0",
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.5.0",
86
- "jest": "^28.1.3",
87
- "jest-jasmine2": "^28.1.3",
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.78.0",
91
+ "rollup": "^2.79.0",
92
92
  "rollup-plugin-terser": "^7.0.2",
93
- "semantic-release": "^19.0.3",
93
+ "semantic-release": "^19.0.5",
94
94
  "tslib": "^2.4.0",
95
- "typedoc": "^0.23.10",
96
- "typedoc-plugin-markdown": "^3.13.4",
97
- "typescript": "^4.7.4"
95
+ "typedoc": "^0.23.13",
96
+ "typedoc-plugin-markdown": "^3.13.5",
97
+ "typescript": "^4.8.2"
98
+ },
99
+ "resolutions": {
100
+ "npm/libnpmversion": "^3.0.6"
98
101
  }
99
102
  }
Binary file