graphql-http 1.18.0 → 1.20.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.mjs CHANGED
@@ -5,12 +5,8 @@
5
5
  */
6
6
  import { validate as graphqlValidate, specifiedRules, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
7
7
  import { areGraphQLErrors, isAsyncIterable, isExecutionResult, isGraphQLError, isObject, jsonErrorReplacer, } from './utils.mjs';
8
- /**
9
- * Checks whether the passed value is the `graphql-http` server agnostic response.
10
- *
11
- * @category Server
12
- */
13
- export function isResponse(val) {
8
+ /** Checks whether the passed value is the `graphql-http` server agnostic response. */
9
+ function isResponse(val) {
14
10
  // TODO: make sure the contents of init match ResponseInit
15
11
  return (Array.isArray(val) &&
16
12
  (typeof val[0] === 'string' || val[0] === null) &&
@@ -18,7 +14,7 @@ export function isResponse(val) {
18
14
  }
19
15
  /**
20
16
  * Makes a GraphQL over HTTP spec compliant server handler. The handler can
21
- * be used with your favourite server library.
17
+ * be used with your favorite server library.
22
18
  *
23
19
  * Beware that the handler resolves only after the whole operation completes.
24
20
  *
@@ -72,23 +68,32 @@ export function isResponse(val) {
72
68
  * @category Server
73
69
  */
74
70
  export function createHandler(options) {
75
- const { schema, context, validate = graphqlValidate, validationRules = [], execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, formatError = (err) => err, } = options;
71
+ const { schema, context, validate = graphqlValidate, validationRules = [], execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, formatError = (err) => err, parseRequestParams = defaultParseRequestParams, } = options;
76
72
  return async function handler(req) {
77
- var _a, _b;
78
- const method = req.method;
79
- if (method !== 'GET' && method !== 'POST') {
80
- return [
81
- null,
82
- {
83
- status: 405,
84
- statusText: 'Method Not Allowed',
85
- headers: {
86
- allow: 'GET, POST',
87
- },
88
- },
89
- ];
73
+ let acceptedMediaType = null;
74
+ const accepts = (getHeader(req, 'accept') || '*/*')
75
+ .replace(/\s/g, '')
76
+ .toLowerCase()
77
+ .split(',');
78
+ for (const accept of accepts) {
79
+ // accept-charset became obsolete, shouldnt be used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset)
80
+ // TODO: handle the weight parameter "q"
81
+ const [mediaType, ...params] = accept.split(';');
82
+ const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified;
83
+ if (mediaType === 'application/graphql-response+json' &&
84
+ charset === 'charset=utf8') {
85
+ acceptedMediaType = 'application/graphql-response+json';
86
+ break;
87
+ }
88
+ // application/json should be the default until watershed
89
+ if ((mediaType === 'application/json' ||
90
+ mediaType === 'application/*' ||
91
+ mediaType === '*/*') &&
92
+ charset === 'charset=utf8') {
93
+ acceptedMediaType = 'application/json';
94
+ break;
95
+ }
90
96
  }
91
- const acceptedMediaType = getAcceptableMediaType(getHeader(req, 'accept'));
92
97
  if (!acceptedMediaType) {
93
98
  return [
94
99
  null,
@@ -101,89 +106,14 @@ export function createHandler(options) {
101
106
  },
102
107
  ];
103
108
  }
104
- // TODO: should graphql-http care about content-encoding? I'd say unzipping should happen before handler is reached
105
- const [mediaType, charset = 'charset=utf-8', // utf-8 is assumed when not specified. this parameter is either "charset" or "boundary" (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length)
106
- ] = (getHeader(req, 'content-type') || '')
107
- .replace(/\s/g, '')
108
- .toLowerCase()
109
- .split(';');
110
109
  let params;
111
110
  try {
112
- const partParams = {};
113
- switch (true) {
114
- case method === 'GET': {
115
- // TODO: what if content-type is specified and is not application/x-www-form-urlencoded?
116
- try {
117
- const [, search] = req.url.split('?');
118
- const searchParams = new URLSearchParams(search);
119
- partParams.operationName =
120
- (_a = searchParams.get('operationName')) !== null && _a !== void 0 ? _a : undefined;
121
- partParams.query = (_b = searchParams.get('query')) !== null && _b !== void 0 ? _b : undefined;
122
- const variables = searchParams.get('variables');
123
- if (variables)
124
- partParams.variables = JSON.parse(variables);
125
- const extensions = searchParams.get('extensions');
126
- if (extensions)
127
- partParams.extensions = JSON.parse(extensions);
128
- }
129
- catch (_c) {
130
- throw new Error('Unparsable URL');
131
- }
132
- break;
133
- }
134
- case method === 'POST' &&
135
- mediaType === 'application/json' &&
136
- charset === 'charset=utf-8':
137
- {
138
- if (!req.body) {
139
- throw new Error('Missing body');
140
- }
141
- let data;
142
- try {
143
- const body = typeof req.body === 'function' ? await req.body() : req.body;
144
- data = typeof body === 'string' ? JSON.parse(body) : body;
145
- }
146
- catch (err) {
147
- throw new Error('Unparsable JSON body');
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;
156
- break;
157
- }
158
- default: // graphql-http doesnt support any other content type
159
- return [
160
- null,
161
- {
162
- status: 415,
163
- statusText: 'Unsupported Media Type',
164
- },
165
- ];
166
- }
167
- if (partParams.query == null)
168
- throw new Error('Missing query');
169
- if (typeof partParams.query !== 'string')
170
- throw new Error('Invalid query');
171
- if (partParams.variables != null &&
172
- (typeof partParams.variables !== 'object' ||
173
- Array.isArray(partParams.variables))) {
174
- throw new Error('Invalid variables');
175
- }
176
- if (partParams.operationName != null &&
177
- typeof partParams.operationName !== 'string') {
178
- throw new Error('Invalid operationName');
179
- }
180
- if (partParams.extensions != null &&
181
- (typeof partParams.extensions !== 'object' ||
182
- Array.isArray(partParams.extensions))) {
183
- throw new Error('Invalid extensions');
184
- }
185
- // request parameters are checked and now complete
186
- params = partParams;
111
+ let paramsOrRes = await parseRequestParams(req);
112
+ if (!paramsOrRes)
113
+ paramsOrRes = await defaultParseRequestParams(req);
114
+ if (isResponse(paramsOrRes))
115
+ return paramsOrRes;
116
+ params = paramsOrRes;
187
117
  }
188
118
  catch (err) {
189
119
  return makeResponse(err, acceptedMediaType, formatError);
@@ -245,7 +175,7 @@ export function createHandler(options) {
245
175
  throw null;
246
176
  operation = ast.operation;
247
177
  }
248
- catch (_d) {
178
+ catch (_a) {
249
179
  return makeResponse(new GraphQLError('Unable to detect operation AST'), acceptedMediaType, formatError);
250
180
  }
251
181
  if (operation === 'subscription') {
@@ -253,7 +183,7 @@ export function createHandler(options) {
253
183
  }
254
184
  // mutations cannot happen over GETs
255
185
  // https://graphql.github.io/graphql-over-http/draft/#sel-CALFJRPAAELBAAxwP
256
- if (operation === 'mutation' && method === 'GET') {
186
+ if (operation === 'mutation' && req.method === 'GET') {
257
187
  return [
258
188
  JSON.stringify({
259
189
  errors: [new GraphQLError('Cannot perform mutations over GET')],
@@ -289,36 +219,108 @@ export function createHandler(options) {
289
219
  };
290
220
  }
291
221
  /**
292
- * Inspects the request and detects the appropriate/acceptable Media-Type
293
- * looking at the `Accept` header while complying with the GraphQL over HTTP spec.
222
+ * The default request params parser. Used when no custom one is provided or if it
223
+ * returns nothing.
294
224
  *
295
- * @category Server
225
+ * Read more about it in {@link ParseRequestParams}.
226
+ *
227
+ * TODO: should graphql-http itself care about content-encoding? I'd say unzipping should happen before handler is reached
296
228
  */
297
- export function getAcceptableMediaType(acceptHeader) {
298
- let acceptedMediaType = null;
299
- const accepts = (acceptHeader || '*/*')
229
+ async function defaultParseRequestParams(req) {
230
+ var _a, _b;
231
+ const method = req.method;
232
+ if (method !== 'GET' && method !== 'POST') {
233
+ return [
234
+ null,
235
+ {
236
+ status: 405,
237
+ statusText: 'Method Not Allowed',
238
+ headers: {
239
+ allow: 'GET, POST',
240
+ },
241
+ },
242
+ ];
243
+ }
244
+ const [mediaType, charset = 'charset=utf-8', // utf-8 is assumed when not specified. this parameter is either "charset" or "boundary" (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length)
245
+ ] = (getHeader(req, 'content-type') || '')
300
246
  .replace(/\s/g, '')
301
247
  .toLowerCase()
302
- .split(',');
303
- for (const accept of accepts) {
304
- // accept-charset became obsolete, shouldnt be used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset)
305
- // TODO: handle the weight parameter "q"
306
- const [mediaType, ...params] = accept.split(';');
307
- const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified;
308
- if (mediaType === 'application/graphql-response+json' &&
309
- charset === 'charset=utf8') {
310
- acceptedMediaType = 'application/graphql-response+json';
311
- break;
312
- }
313
- if ((mediaType === 'application/json' ||
314
- mediaType === 'application/*' ||
315
- mediaType === '*/*') &&
316
- charset === 'charset=utf8') {
317
- acceptedMediaType = 'application/json';
248
+ .split(';');
249
+ const partParams = {};
250
+ switch (true) {
251
+ case method === 'GET': {
252
+ // TODO: what if content-type is specified and is not application/x-www-form-urlencoded?
253
+ try {
254
+ const [, search] = req.url.split('?');
255
+ const searchParams = new URLSearchParams(search);
256
+ partParams.operationName =
257
+ (_a = searchParams.get('operationName')) !== null && _a !== void 0 ? _a : undefined;
258
+ partParams.query = (_b = searchParams.get('query')) !== null && _b !== void 0 ? _b : undefined;
259
+ const variables = searchParams.get('variables');
260
+ if (variables)
261
+ partParams.variables = JSON.parse(variables);
262
+ const extensions = searchParams.get('extensions');
263
+ if (extensions)
264
+ partParams.extensions = JSON.parse(extensions);
265
+ }
266
+ catch (_c) {
267
+ throw new Error('Unparsable URL');
268
+ }
318
269
  break;
319
270
  }
271
+ case method === 'POST' &&
272
+ mediaType === 'application/json' &&
273
+ charset === 'charset=utf-8':
274
+ {
275
+ if (!req.body) {
276
+ throw new Error('Missing body');
277
+ }
278
+ let data;
279
+ try {
280
+ const body = typeof req.body === 'function' ? await req.body() : req.body;
281
+ data = typeof body === 'string' ? JSON.parse(body) : body;
282
+ }
283
+ catch (err) {
284
+ throw new Error('Unparsable JSON body');
285
+ }
286
+ if (!isObject(data)) {
287
+ throw new Error('JSON body must be an object');
288
+ }
289
+ partParams.operationName = data.operationName;
290
+ partParams.query = data.query;
291
+ partParams.variables = data.variables;
292
+ partParams.extensions = data.extensions;
293
+ break;
294
+ }
295
+ default: // graphql-http doesnt support any other content type
296
+ return [
297
+ null,
298
+ {
299
+ status: 415,
300
+ statusText: 'Unsupported Media Type',
301
+ },
302
+ ];
303
+ }
304
+ if (partParams.query == null)
305
+ throw new Error('Missing query');
306
+ if (typeof partParams.query !== 'string')
307
+ throw new Error('Invalid query');
308
+ if (partParams.variables != null &&
309
+ (typeof partParams.variables !== 'object' ||
310
+ Array.isArray(partParams.variables))) {
311
+ throw new Error('Invalid variables');
312
+ }
313
+ if (partParams.operationName != null &&
314
+ typeof partParams.operationName !== 'string') {
315
+ throw new Error('Invalid operationName');
320
316
  }
321
- return acceptedMediaType;
317
+ if (partParams.extensions != null &&
318
+ (typeof partParams.extensions !== 'object' ||
319
+ Array.isArray(partParams.extensions))) {
320
+ throw new Error('Invalid extensions');
321
+ }
322
+ // request parameters are checked and now complete
323
+ return partParams;
322
324
  }
323
325
  /**
324
326
  * Creates an appropriate GraphQL over HTTP response following the provided arguments.
@@ -330,10 +332,8 @@ export function getAcceptableMediaType(acceptHeader) {
330
332
  *
331
333
  * If the first argument is an `Error`, the operation will be treated as a bad request responding with `400: Bad Request` and the
332
334
  * error will be present in the `ExecutionResult` style.
333
- *
334
- * @category Server
335
335
  */
336
- export function makeResponse(resultOrErrors, acceptedMediaType, formatError) {
336
+ function makeResponse(resultOrErrors, acceptedMediaType, formatError) {
337
337
  if (resultOrErrors instanceof Error &&
338
338
  // because GraphQLError extends the Error class
339
339
  !isGraphQLError(resultOrErrors)) {
@@ -21,7 +21,6 @@ const handler_1 = require("../handler");
21
21
  * @category Server/express
22
22
  */
23
23
  function createHandler(options) {
24
- const isProd = process.env.NODE_ENV === 'production';
25
24
  const handle = (0, handler_1.createHandler)(options);
26
25
  return async function requestListener(req, res) {
27
26
  try {
@@ -50,23 +49,7 @@ function createHandler(options) {
50
49
  // If you wish to handle them differently, consider implementing your own request handler.
51
50
  console.error('Internal error occurred during request handling. ' +
52
51
  'Please check your implementation.', err);
53
- if (isProd) {
54
- res.writeHead(500).end();
55
- }
56
- else {
57
- res
58
- .writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
59
- .end(JSON.stringify({
60
- errors: [
61
- err instanceof Error
62
- ? {
63
- message: err.message,
64
- stack: err.stack,
65
- }
66
- : err,
67
- ],
68
- }));
69
- }
52
+ res.writeHead(500).end();
70
53
  }
71
54
  };
72
55
  }
@@ -18,7 +18,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
18
18
  * @category Server/express
19
19
  */
20
20
  export function createHandler(options) {
21
- const isProd = process.env.NODE_ENV === 'production';
22
21
  const handle = createRawHandler(options);
23
22
  return async function requestListener(req, res) {
24
23
  try {
@@ -47,23 +46,7 @@ export function createHandler(options) {
47
46
  // If you wish to handle them differently, consider implementing your own request handler.
48
47
  console.error('Internal error occurred during request handling. ' +
49
48
  'Please check your implementation.', err);
50
- if (isProd) {
51
- res.writeHead(500).end();
52
- }
53
- else {
54
- res
55
- .writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
56
- .end(JSON.stringify({
57
- errors: [
58
- err instanceof Error
59
- ? {
60
- message: err.message,
61
- stack: err.stack,
62
- }
63
- : err,
64
- ],
65
- }));
66
- }
49
+ res.writeHead(500).end();
67
50
  }
68
51
  };
69
52
  }
@@ -21,7 +21,6 @@ const handler_1 = require("../handler");
21
21
  * @category Server/fastify
22
22
  */
23
23
  function createHandler(options) {
24
- const isProd = process.env.NODE_ENV === 'production';
25
24
  const handle = (0, handler_1.createHandler)(options);
26
25
  return async function requestListener(req, reply) {
27
26
  try {
@@ -45,24 +44,7 @@ function createHandler(options) {
45
44
  // If you wish to handle them differently, consider implementing your own request handler.
46
45
  console.error('Internal error occurred during request handling. ' +
47
46
  'Please check your implementation.', err);
48
- if (isProd) {
49
- reply.status(500).send();
50
- }
51
- else {
52
- reply
53
- .status(500)
54
- .header('content-type', 'application/json; charset=utf-8')
55
- .send({
56
- errors: [
57
- err instanceof Error
58
- ? {
59
- message: err.message,
60
- stack: err.stack,
61
- }
62
- : err,
63
- ],
64
- });
65
- }
47
+ reply.status(500).send();
66
48
  }
67
49
  };
68
50
  }
@@ -18,7 +18,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
18
18
  * @category Server/fastify
19
19
  */
20
20
  export function createHandler(options) {
21
- const isProd = process.env.NODE_ENV === 'production';
22
21
  const handle = createRawHandler(options);
23
22
  return async function requestListener(req, reply) {
24
23
  try {
@@ -42,24 +41,7 @@ export function createHandler(options) {
42
41
  // If you wish to handle them differently, consider implementing your own request handler.
43
42
  console.error('Internal error occurred during request handling. ' +
44
43
  'Please check your implementation.', err);
45
- if (isProd) {
46
- reply.status(500).send();
47
- }
48
- else {
49
- reply
50
- .status(500)
51
- .header('content-type', 'application/json; charset=utf-8')
52
- .send({
53
- errors: [
54
- err instanceof Error
55
- ? {
56
- message: err.message,
57
- stack: err.stack,
58
- }
59
- : err,
60
- ],
61
- });
62
- }
44
+ reply.status(500).send();
63
45
  }
64
46
  };
65
47
  }
@@ -26,7 +26,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
26
26
  * import http from 'http';
27
27
  * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
28
28
  * import { createHandler } from 'graphql-http/lib/use/fetch';
29
- * import { schema } from './my-graphql-step/index.mjs';
29
+ * import { schema } from './my-graphql-schema/index.mjs';
30
30
  *
31
31
  * // Use this adapter in _any_ environment.
32
32
  * const adapter = createServerAdapter({
@@ -26,7 +26,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
26
26
  * import http from 'http';
27
27
  * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
28
28
  * import { createHandler } from 'graphql-http/lib/use/fetch';
29
- * import { schema } from './my-graphql-step';
29
+ * import { schema } from './my-graphql-schema';
30
30
  *
31
31
  * // Use this adapter in _any_ environment.
32
32
  * const adapter = createServerAdapter({
package/lib/use/fetch.js CHANGED
@@ -13,7 +13,7 @@ const handler_1 = require("../handler");
13
13
  * import http from 'http';
14
14
  * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
15
15
  * import { createHandler } from 'graphql-http/lib/use/fetch';
16
- * import { schema } from './my-graphql-step';
16
+ * import { schema } from './my-graphql-schema';
17
17
  *
18
18
  * // Use this adapter in _any_ environment.
19
19
  * const adapter = createServerAdapter({
@@ -31,7 +31,6 @@ const handler_1 = require("../handler");
31
31
  * @category Server/fetch
32
32
  */
33
33
  function createHandler(options, reqCtx = {}) {
34
- const isProd = process.env.NODE_ENV === 'production';
35
34
  const api = {
36
35
  Response: reqCtx.Response || Response,
37
36
  TextEncoder: reqCtx.TextEncoder || TextEncoder,
@@ -55,26 +54,7 @@ function createHandler(options, reqCtx = {}) {
55
54
  // If you wish to handle them differently, consider implementing your own request handler.
56
55
  console.error('Internal error occurred during request handling. ' +
57
56
  '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
- }
57
+ return new api.Response(null, { status: 500 });
78
58
  }
79
59
  };
80
60
  }
package/lib/use/fetch.mjs CHANGED
@@ -10,7 +10,7 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
10
10
  * import http from 'http';
11
11
  * import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
12
12
  * import { createHandler } from 'graphql-http/lib/use/fetch';
13
- * import { schema } from './my-graphql-step/index.mjs';
13
+ * import { schema } from './my-graphql-schema/index.mjs';
14
14
  *
15
15
  * // Use this adapter in _any_ environment.
16
16
  * const adapter = createServerAdapter({
@@ -28,7 +28,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
28
28
  * @category Server/fetch
29
29
  */
30
30
  export function createHandler(options, reqCtx = {}) {
31
- const isProd = process.env.NODE_ENV === 'production';
32
31
  const api = {
33
32
  Response: reqCtx.Response || Response,
34
33
  TextEncoder: reqCtx.TextEncoder || TextEncoder,
@@ -52,26 +51,7 @@ export function createHandler(options, reqCtx = {}) {
52
51
  // If you wish to handle them differently, consider implementing your own request handler.
53
52
  console.error('Internal error occurred during request handling. ' +
54
53
  '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
- }
54
+ return new api.Response(null, { status: 500 });
75
55
  }
76
56
  };
77
57
  }
@@ -22,7 +22,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
22
22
  * ```js
23
23
  * import http from 'http';
24
24
  * import { createHandler } from 'graphql-http/lib/use/http';
25
- * import { schema } from './my-graphql-step/index.mjs';
25
+ * import { schema } from './my-graphql-schema/index.mjs';
26
26
  *
27
27
  * const server = http.createServer(createHandler({ schema }));
28
28
  *
package/lib/use/http.d.ts CHANGED
@@ -22,7 +22,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
22
22
  * ```js
23
23
  * import http from 'http';
24
24
  * import { createHandler } from 'graphql-http/lib/use/http';
25
- * import { schema } from './my-graphql-step';
25
+ * import { schema } from './my-graphql-schema';
26
26
  *
27
27
  * const server = http.createServer(createHandler({ schema }));
28
28
  *
package/lib/use/http.js CHANGED
@@ -9,7 +9,7 @@ const handler_1 = require("../handler");
9
9
  * ```js
10
10
  * import http from 'http';
11
11
  * import { createHandler } from 'graphql-http/lib/use/http';
12
- * import { schema } from './my-graphql-step';
12
+ * import { schema } from './my-graphql-schema';
13
13
  *
14
14
  * const server = http.createServer(createHandler({ schema }));
15
15
  *
@@ -20,7 +20,6 @@ const handler_1 = require("../handler");
20
20
  * @category Server/http
21
21
  */
22
22
  function createHandler(options) {
23
- const isProd = process.env.NODE_ENV === 'production';
24
23
  const handle = (0, handler_1.createHandler)(options);
25
24
  return async function requestListener(req, res) {
26
25
  try {
@@ -49,23 +48,7 @@ function createHandler(options) {
49
48
  // If you wish to handle them differently, consider implementing your own request handler.
50
49
  console.error('Internal error occurred during request handling. ' +
51
50
  '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
- }
51
+ res.writeHead(500).end();
69
52
  }
70
53
  };
71
54
  }