graphql-http 0.2.0 → 1.0.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/{LICENSE → LICENSE.md} +2 -2
- package/README.md +641 -35
- package/lib/client.d.ts +147 -0
- package/lib/client.js +189 -0
- package/lib/client.mjs +170 -0
- package/lib/common.d.ts +98 -0
- package/lib/common.js +19 -0
- package/lib/common.mjs +15 -0
- package/lib/handler.d.ts +155 -0
- package/lib/handler.js +314 -0
- package/lib/handler.mjs +310 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +18 -188
- package/lib/index.mjs +3 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +13 -0
- package/lib/utils.mjs +9 -0
- package/package.json +87 -25
- package/umd/graphql-http.js +206 -0
- package/umd/graphql-http.min.js +1 -0
- package/umd/graphql-http.min.js.gz +0 -0
- package/.eslintrc.json +0 -8
- package/.npmignore +0 -33
- package/index.js +0 -1
- package/lib/__tests__/index.js +0 -90
package/lib/handler.mjs
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* handler
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
import { validate as graphqlValidate, execute as graphqlExecute, parse, getOperationAST, } from 'graphql';
|
|
7
|
+
import { isResponse } from './common.mjs';
|
|
8
|
+
/**
|
|
9
|
+
* Makes a GraphQL over HTTP Protocol compliant server handler. The handler can
|
|
10
|
+
* be used with your favourite server library.
|
|
11
|
+
*
|
|
12
|
+
* Beware that the handler resolves only after the whole operation completes.
|
|
13
|
+
*
|
|
14
|
+
* Errors thrown from **any** of the provided options or callbacks (or even due to
|
|
15
|
+
* library misuse or potential bugs) will reject the handler's promise. They are
|
|
16
|
+
* considered internal errors and you should take care of them accordingly.
|
|
17
|
+
*
|
|
18
|
+
* For production environments, its recommended not to transmit the exact internal
|
|
19
|
+
* error details to the client, but instead report to an error logging tool or simply
|
|
20
|
+
* the console.
|
|
21
|
+
*
|
|
22
|
+
* Simple example usage with Node:
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* import http from 'http';
|
|
26
|
+
* import { createHandler } from 'graphql-http';
|
|
27
|
+
* import { schema } from './my-graphql-schema.mjs';
|
|
28
|
+
*
|
|
29
|
+
* // Create the GraphQL over HTTP handler
|
|
30
|
+
* const handler = createHandler({ schema });
|
|
31
|
+
*
|
|
32
|
+
* // Create a HTTP server using the handler on `/graphql`
|
|
33
|
+
* const server = http.createServer(async (req, res) => {
|
|
34
|
+
* if (!req.url.startsWith('/graphql')) {
|
|
35
|
+
* return res.writeHead(404).end();
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* try {
|
|
39
|
+
* const [body, init] = await handler({
|
|
40
|
+
* url: req.url,
|
|
41
|
+
* method: req.method,
|
|
42
|
+
* headers: req.headers,
|
|
43
|
+
* body: await new Promise((resolve) => {
|
|
44
|
+
* let body = '';
|
|
45
|
+
* req.on('data', (chunk) => (body += chunk));
|
|
46
|
+
* req.on('end', () => resolve(body));
|
|
47
|
+
* }),
|
|
48
|
+
* raw: req,
|
|
49
|
+
* });
|
|
50
|
+
* res.writeHead(init.status, init.statusText, init.headers).end(body);
|
|
51
|
+
* } catch (err) {
|
|
52
|
+
* // BEWARE not to transmit the exact internal error message in production environments
|
|
53
|
+
* res.writeHead(500).end(err.message);
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* server.listen(4000);
|
|
58
|
+
* console.log('Listening to port 4000');
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @category Server
|
|
62
|
+
*/
|
|
63
|
+
export function createHandler(options) {
|
|
64
|
+
const { schema, context, validate = graphqlValidate, execute = graphqlExecute, onSubscribe, onOperation, } = options;
|
|
65
|
+
return async function handler(req) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const method = req.method;
|
|
68
|
+
if (method !== 'GET' && method !== 'POST') {
|
|
69
|
+
return [
|
|
70
|
+
null,
|
|
71
|
+
{
|
|
72
|
+
status: 405,
|
|
73
|
+
statusText: 'Method Not Allowed',
|
|
74
|
+
headers: {
|
|
75
|
+
allow: 'GET, POST',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
let acceptedMediaType;
|
|
81
|
+
const accepts = (req.headers.accept || '*/*')
|
|
82
|
+
.replace(/\s/g, '')
|
|
83
|
+
.toLowerCase()
|
|
84
|
+
.split(',');
|
|
85
|
+
for (const accept of accepts) {
|
|
86
|
+
// accept-charset became obsolete, shouldnt be used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset)
|
|
87
|
+
// TODO: handle the weight parameter "q"
|
|
88
|
+
const [mediaType, ...params] = accept.split(';');
|
|
89
|
+
const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified;
|
|
90
|
+
if (mediaType === 'application/json' && charset === 'charset=utf8') {
|
|
91
|
+
acceptedMediaType = 'application/json';
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if ((mediaType === 'application/graphql+json' ||
|
|
95
|
+
mediaType === 'application/*' ||
|
|
96
|
+
mediaType === '*/*') &&
|
|
97
|
+
charset === 'charset=utf8') {
|
|
98
|
+
acceptedMediaType = 'application/graphql+json';
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!acceptedMediaType) {
|
|
103
|
+
return [
|
|
104
|
+
null,
|
|
105
|
+
{
|
|
106
|
+
status: 406,
|
|
107
|
+
statusText: 'Not Acceptable',
|
|
108
|
+
headers: {
|
|
109
|
+
accept: 'application/graphql+json; charset=utf-8, application/json; charset=utf-8',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
// TODO: should graphql-http care about content-encoding? I'd say unzipping should happen before handler is reached
|
|
115
|
+
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)
|
|
116
|
+
] = (req.headers['content-type'] || '')
|
|
117
|
+
.replace(/\s/g, '')
|
|
118
|
+
.toLowerCase()
|
|
119
|
+
.split(';');
|
|
120
|
+
let params;
|
|
121
|
+
try {
|
|
122
|
+
const partParams = {};
|
|
123
|
+
switch (true) {
|
|
124
|
+
case method === 'GET': {
|
|
125
|
+
// TODO: what if content-type is specified and is not application/x-www-form-urlencoded?
|
|
126
|
+
try {
|
|
127
|
+
const url = new URL(req.url || '', 'http://localhost/');
|
|
128
|
+
partParams.operationName =
|
|
129
|
+
(_a = url.searchParams.get('operationName')) !== null && _a !== void 0 ? _a : undefined;
|
|
130
|
+
partParams.query = (_b = url.searchParams.get('query')) !== null && _b !== void 0 ? _b : undefined;
|
|
131
|
+
const variables = url.searchParams.get('variables');
|
|
132
|
+
if (variables)
|
|
133
|
+
partParams.variables = JSON.parse(variables);
|
|
134
|
+
const extensions = url.searchParams.get('extensions');
|
|
135
|
+
if (extensions)
|
|
136
|
+
partParams.extensions = JSON.parse(extensions);
|
|
137
|
+
}
|
|
138
|
+
catch (_c) {
|
|
139
|
+
throw new Error('Unparsable URL');
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case method === 'POST' &&
|
|
144
|
+
mediaType === 'application/json' &&
|
|
145
|
+
charset === 'charset=utf-8':
|
|
146
|
+
{
|
|
147
|
+
if (!req.body) {
|
|
148
|
+
throw new Error('Missing body');
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;
|
|
152
|
+
partParams.operationName = data.operationName;
|
|
153
|
+
partParams.query = data.query;
|
|
154
|
+
partParams.variables = data.variables;
|
|
155
|
+
partParams.extensions = data.extensions;
|
|
156
|
+
}
|
|
157
|
+
catch (_d) {
|
|
158
|
+
throw new Error('Unparsable JSON body');
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default: // graphql-http doesnt support any other content type
|
|
163
|
+
return [
|
|
164
|
+
null,
|
|
165
|
+
{
|
|
166
|
+
status: 415,
|
|
167
|
+
statusText: 'Unsupported Media Type',
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
if (!partParams.query)
|
|
172
|
+
throw new Error('Missing query');
|
|
173
|
+
if (partParams.variables != null &&
|
|
174
|
+
(typeof partParams.variables !== 'object' ||
|
|
175
|
+
Array.isArray(partParams.variables))) {
|
|
176
|
+
throw new Error('Invalid variables');
|
|
177
|
+
}
|
|
178
|
+
if (partParams.extensions != null &&
|
|
179
|
+
(typeof partParams.extensions !== 'object' ||
|
|
180
|
+
Array.isArray(partParams.extensions))) {
|
|
181
|
+
throw new Error('Invalid extensions');
|
|
182
|
+
}
|
|
183
|
+
// request parameters are checked and now complete
|
|
184
|
+
params = partParams;
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
return [
|
|
188
|
+
err.message,
|
|
189
|
+
{
|
|
190
|
+
status: acceptedMediaType === 'application/json' ? 200 : 400,
|
|
191
|
+
statusText: 'Bad Request',
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
let args;
|
|
196
|
+
const maybeResOrExecArgs = await (onSubscribe === null || onSubscribe === void 0 ? void 0 : onSubscribe(req, params));
|
|
197
|
+
if (isResponse(maybeResOrExecArgs))
|
|
198
|
+
return maybeResOrExecArgs;
|
|
199
|
+
else if (maybeResOrExecArgs)
|
|
200
|
+
args = maybeResOrExecArgs;
|
|
201
|
+
else {
|
|
202
|
+
if (!schema)
|
|
203
|
+
throw new Error('The GraphQL schema is not provided');
|
|
204
|
+
const { operationName, query, variables } = params;
|
|
205
|
+
let document;
|
|
206
|
+
try {
|
|
207
|
+
document = parse(query);
|
|
208
|
+
}
|
|
209
|
+
catch (_e) {
|
|
210
|
+
return [
|
|
211
|
+
'GraphQL query syntax error',
|
|
212
|
+
{
|
|
213
|
+
status: acceptedMediaType === 'application/json' ? 200 : 400,
|
|
214
|
+
statusText: 'Bad Request',
|
|
215
|
+
},
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
const argsWithoutSchema = {
|
|
219
|
+
operationName,
|
|
220
|
+
document,
|
|
221
|
+
variableValues: variables,
|
|
222
|
+
};
|
|
223
|
+
if (typeof schema === 'function') {
|
|
224
|
+
const resOrSchema = await schema(req, argsWithoutSchema);
|
|
225
|
+
if (isResponse(resOrSchema))
|
|
226
|
+
return resOrSchema;
|
|
227
|
+
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema: resOrSchema });
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
let operation;
|
|
234
|
+
try {
|
|
235
|
+
const ast = getOperationAST(args.document, args.operationName);
|
|
236
|
+
if (!ast)
|
|
237
|
+
throw null;
|
|
238
|
+
operation = ast.operation;
|
|
239
|
+
}
|
|
240
|
+
catch (_f) {
|
|
241
|
+
return [
|
|
242
|
+
'Unable to detect operation AST',
|
|
243
|
+
{
|
|
244
|
+
status: acceptedMediaType === 'application/json' ? 200 : 400,
|
|
245
|
+
statusText: 'Bad Request',
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
if (operation === 'subscription') {
|
|
250
|
+
return [
|
|
251
|
+
'Subscriptions are not supported',
|
|
252
|
+
{
|
|
253
|
+
status: 400,
|
|
254
|
+
statusText: 'Bad Request',
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
// mutations cannot happen over GETs
|
|
259
|
+
// https://graphql.github.io/graphql-over-http/draft/#sel-CALFJRPAAELBAAxwP
|
|
260
|
+
if (operation === 'mutation' && method === 'GET') {
|
|
261
|
+
return [
|
|
262
|
+
'Cannot perform mutations over GET',
|
|
263
|
+
{
|
|
264
|
+
status: 405,
|
|
265
|
+
statusText: 'Method Not Allowed',
|
|
266
|
+
headers: {
|
|
267
|
+
allow: 'POST',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
if (!('contextValue' in args)) {
|
|
273
|
+
args.contextValue =
|
|
274
|
+
typeof context === 'function' ? await context(req, args) : context;
|
|
275
|
+
}
|
|
276
|
+
const validationErrs = validate(args.schema, args.document);
|
|
277
|
+
if (validationErrs.length) {
|
|
278
|
+
return [
|
|
279
|
+
JSON.stringify({ errors: validationErrs }),
|
|
280
|
+
{
|
|
281
|
+
status: acceptedMediaType === 'application/json' ? 200 : 400,
|
|
282
|
+
statusText: 'Bad Request',
|
|
283
|
+
headers: {
|
|
284
|
+
'content-type': acceptedMediaType === 'application/json'
|
|
285
|
+
? 'application/json; charset=utf-8'
|
|
286
|
+
: 'application/graphql+json; charset=utf-8',
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
let result = await execute(args);
|
|
292
|
+
const maybeResOrResult = await (onOperation === null || onOperation === void 0 ? void 0 : onOperation(req, args, result));
|
|
293
|
+
if (isResponse(maybeResOrResult))
|
|
294
|
+
return maybeResOrResult;
|
|
295
|
+
else if (maybeResOrResult)
|
|
296
|
+
result = maybeResOrResult;
|
|
297
|
+
return [
|
|
298
|
+
JSON.stringify(result),
|
|
299
|
+
{
|
|
300
|
+
status: 200,
|
|
301
|
+
statusText: 'OK',
|
|
302
|
+
headers: {
|
|
303
|
+
'content-type': acceptedMediaType === 'application/json'
|
|
304
|
+
? 'application/json; charset=utf-8'
|
|
305
|
+
: 'application/graphql+json; charset=utf-8',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
];
|
|
309
|
+
};
|
|
310
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -1,189 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require('isomorphic-fetch');
|
|
8
|
-
|
|
9
|
-
function GQLClient (url, options) {
|
|
10
|
-
if (!(this instanceof GQLClient)) {
|
|
11
|
-
return new GQLClient(url, options);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (options == null) {
|
|
15
|
-
options = {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (url == null) {
|
|
19
|
-
throw new TypeError('GQLClient must have a url');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.url = url;
|
|
23
|
-
this.options = Object.assign({method: 'get'}, options);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
GQLClient.prototype.configure = function (options) {
|
|
27
|
-
return new GQLClient(this.url, merge({}, this.options, options));
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
GQLClient.prototype.query = function (query, variables) {
|
|
31
|
-
if (query == null) {
|
|
32
|
-
throw new TypeError('got ' + query + ' for GQLClient#query query');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (variables == null) {
|
|
36
|
-
variables = {};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var params = qs.stringify({
|
|
40
|
-
query: query,
|
|
41
|
-
variables: JSON.stringify(variables)
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
var requestUrl = this.options.onlyBody ? (
|
|
45
|
-
this.url
|
|
46
|
-
) : (
|
|
47
|
-
this.url + '?' + params
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
var method = this.options.method.toLowerCase();
|
|
51
|
-
|
|
52
|
-
if (method === 'get') {
|
|
53
|
-
var fetchOptions = this.options.fetch;
|
|
54
|
-
} else if (method === 'post') {
|
|
55
|
-
var fetchOptions = merge({
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'content-type': 'application/json'
|
|
59
|
-
},
|
|
60
|
-
body: JSON.stringify({query: query, variables: variables})
|
|
61
|
-
}, this.options.fetch);
|
|
62
|
-
} else {
|
|
63
|
-
throw new TypeError('Unknown value "' + method + '" for method parameter');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return fetch(requestUrl, fetchOptions)
|
|
67
|
-
.then(handleResponse);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
GQLClient.prototype.mutate = function (query, variables) {
|
|
71
|
-
if (this.options.method.toLowerCase() !== 'post') {
|
|
72
|
-
return this.configure({method: 'post'}).query(query, variables);
|
|
73
|
-
} else {
|
|
74
|
-
return this.query(query, variables);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
exports.GQLClient = GQLClient;
|
|
79
|
-
|
|
80
|
-
function handleResponse (resp) {
|
|
81
|
-
if (resp.ok) {
|
|
82
|
-
return handleOkayResponse(resp);
|
|
83
|
-
} else if (/json/.test(resp.headers.get('Content-Type'))) {
|
|
84
|
-
return handleJSONErrorResponse(resp);
|
|
85
|
-
} else {
|
|
86
|
-
return handleUnknownErrorResponse(resp);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function handleOkayResponse (resp) {
|
|
91
|
-
return resp.json().then(function (body) {
|
|
92
|
-
if (body == null) {
|
|
93
|
-
throw formatErrors(
|
|
94
|
-
'Missing/null body response from GraphQL.',
|
|
95
|
-
body
|
|
96
|
-
);
|
|
97
|
-
} else if (body.errors instanceof Array && body.errors.length > 0) {
|
|
98
|
-
throw formatErrors(
|
|
99
|
-
'Received ' + body.errors.length + ' error(s) from GraphQL.',
|
|
100
|
-
body
|
|
101
|
-
);
|
|
102
|
-
} else {
|
|
103
|
-
return body;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
104
7
|
}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
[
|
|
118
|
-
message,
|
|
119
|
-
'Unrecognized body structure "' + JSON.stringify(body) + '"'
|
|
120
|
-
].join('\n')
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function handleJSONErrorResponse (resp, body) {
|
|
126
|
-
return resp.json().then(function (body) {
|
|
127
|
-
var message = 'Received status ' + resp.status + ' from GraphQL.';
|
|
128
|
-
|
|
129
|
-
throw formatErrors(message, body);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function errorToMessage (error) {
|
|
134
|
-
if (error != null && error.message != null) {
|
|
135
|
-
return error.message;
|
|
136
|
-
} else {
|
|
137
|
-
return JSON.stringify(error);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function handleUnknownErrorResponse (resp) {
|
|
142
|
-
var message = 'Received status ' + resp.status + ' from GraphQL.';
|
|
143
|
-
|
|
144
|
-
throw formatErrors(message, {
|
|
145
|
-
errors: [{
|
|
146
|
-
message: 'Unknown content type "' + resp.headers.get('Content-Type') + '".'
|
|
147
|
-
}]
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function GraphQLError (message) {
|
|
152
|
-
this.message = message;
|
|
153
|
-
|
|
154
|
-
if (message instanceof Error) {
|
|
155
|
-
this.message = message.message;
|
|
156
|
-
this.stack = message.stack;
|
|
157
|
-
} else if (Error.captureStackTrace) {
|
|
158
|
-
Error.captureStackTrace(this, GraphQLError);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
GraphQLError.prototype = Object.create(Error.prototype);
|
|
163
|
-
GraphQLError.prototype.constructor = GraphQLError;
|
|
164
|
-
|
|
165
|
-
Object.defineProperty(GraphQLError.prototype, 'name', {
|
|
166
|
-
value: 'GraphQLError'
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
exports.GraphQLError = GraphQLError;
|
|
170
|
-
|
|
171
|
-
function GraphQLResponseError (message) {
|
|
172
|
-
this.message = message;
|
|
173
|
-
|
|
174
|
-
if (message instanceof Error) {
|
|
175
|
-
this.message = message.message;
|
|
176
|
-
this.stack = message.stack;
|
|
177
|
-
} else if (Error.captureStackTrace) {
|
|
178
|
-
Error.captureStackTrace(this, GraphQLResponseError);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
GraphQLResponseError.prototype = Object.create(GraphQLError.prototype);
|
|
183
|
-
GraphQLResponseError.prototype.constructor = GraphQLResponseError;
|
|
184
|
-
|
|
185
|
-
Object.defineProperty(GraphQLResponseError.prototype, 'name', {
|
|
186
|
-
value: 'GraphQLResponseError'
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
exports.GraphQLResponseError = GraphQLResponseError;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./handler"), exports);
|
|
19
|
+
__exportStar(require("./client"), exports);
|
package/lib/index.mjs
ADDED
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* utils
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isObject = void 0;
|
|
9
|
+
/** @private */
|
|
10
|
+
function isObject(val) {
|
|
11
|
+
return typeof val === 'object' && val !== null;
|
|
12
|
+
}
|
|
13
|
+
exports.isObject = isObject;
|
package/lib/utils.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,37 +1,99 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "eslint lib && jest"
|
|
7
|
-
},
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/petermelias/graphql-http.git"
|
|
11
|
-
},
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple, plugable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
|
|
12
5
|
"keywords": [
|
|
13
6
|
"graphql",
|
|
7
|
+
"client",
|
|
8
|
+
"relay",
|
|
9
|
+
"express",
|
|
10
|
+
"apollo",
|
|
11
|
+
"server",
|
|
14
12
|
"http",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"fetch"
|
|
13
|
+
"transport",
|
|
14
|
+
"observables",
|
|
15
|
+
"fastify"
|
|
19
16
|
],
|
|
20
|
-
"author": "
|
|
17
|
+
"author": "Denis Badurina <badurinadenis@gmail.com>",
|
|
21
18
|
"license": "MIT",
|
|
22
|
-
"
|
|
23
|
-
|
|
19
|
+
"homepage": "https://github.com/enisdenjo/graphql-http#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/enisdenjo/graphql-http.git"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=12"
|
|
26
|
+
},
|
|
27
|
+
"packageManager": "yarn@3.2.2",
|
|
28
|
+
"main": "lib/index.js",
|
|
29
|
+
"module": "lib/index.mjs",
|
|
30
|
+
"browser": "umd/graphql-http.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"require": "./lib/index.js",
|
|
34
|
+
"import": "./lib/index.mjs",
|
|
35
|
+
"types": "./lib/index.d.ts",
|
|
36
|
+
"browser": "./umd/graphql-http.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"types": "lib/index.d.ts",
|
|
41
|
+
"files": [
|
|
42
|
+
"lib",
|
|
43
|
+
"umd",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE.md"
|
|
46
|
+
],
|
|
47
|
+
"sideEffects": [
|
|
48
|
+
"umd/*"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"gendocs": "typedoc --options typedoc.js src/",
|
|
55
|
+
"lint": "eslint 'src'",
|
|
56
|
+
"type-check": "tsc --noEmit",
|
|
57
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
58
|
+
"build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.js",
|
|
59
|
+
"build:cjs": "tsc -b tsconfig.cjs.json",
|
|
60
|
+
"build:umd": "rollup -c && gzip umd/graphql-http.min.js -c > umd/graphql-http.min.js.gz",
|
|
61
|
+
"build": "yarn build:esm && yarn build:cjs && yarn build:umd",
|
|
62
|
+
"release": "semantic-release"
|
|
24
63
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"isomorphic-fetch": "^2.2.1",
|
|
28
|
-
"lodash.merge": "^4.0.0"
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"graphql": ">=0.11 <=16"
|
|
29
66
|
},
|
|
30
|
-
"peerDependencies": {},
|
|
31
67
|
"devDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
68
|
+
"@babel/core": "^7.18.10",
|
|
69
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
70
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
71
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
|
|
72
|
+
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
|
|
73
|
+
"@babel/preset-env": "^7.18.10",
|
|
74
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
75
|
+
"@rollup/plugin-typescript": "^8.3.4",
|
|
76
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
77
|
+
"@semantic-release/git": "^10.0.1",
|
|
78
|
+
"@types/jest": "^28.1.6",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
|
80
|
+
"@typescript-eslint/parser": "^5.32.0",
|
|
81
|
+
"babel-jest": "^28.1.3",
|
|
82
|
+
"eslint": "^8.21.0",
|
|
83
|
+
"eslint-config-prettier": "^8.5.0",
|
|
84
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
85
|
+
"graphql": "^16.5.0",
|
|
86
|
+
"jest": "^28.1.3",
|
|
87
|
+
"jest-jasmine2": "^28.1.3",
|
|
88
|
+
"node-fetch": "^3.2.10",
|
|
89
|
+
"prettier": "^2.7.1",
|
|
90
|
+
"replacestream": "^4.0.3",
|
|
91
|
+
"rollup": "^2.77.2",
|
|
92
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
93
|
+
"semantic-release": "^19.0.3",
|
|
94
|
+
"tslib": "^2.4.0",
|
|
95
|
+
"typedoc": "^0.23.10",
|
|
96
|
+
"typedoc-plugin-markdown": "^3.13.4",
|
|
97
|
+
"typescript": "^4.7.4"
|
|
36
98
|
}
|
|
37
99
|
}
|