@orion-js/graphql 3.5.1 → 3.5.3
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/errorHandler.js +16 -8
- package/lib/startGraphQL.test.js +59 -0
- package/package.json +8 -8
package/lib/errorHandler.js
CHANGED
|
@@ -4,10 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
8
7
|
const graphql_1 = require("graphql");
|
|
9
8
|
function errorHandler(error, data) {
|
|
10
9
|
const message = `Error in resolver "${data.name}" ${data.model ? `of model "${data.model.name}"` : ''}`;
|
|
10
|
+
const hash = crypto_1.default
|
|
11
|
+
.createHash('sha1')
|
|
12
|
+
.update(error.message, 'utf8')
|
|
13
|
+
.digest('hex')
|
|
14
|
+
.substring(0, 10);
|
|
15
|
+
error.hash = hash;
|
|
11
16
|
if (error && error.isOrionError) {
|
|
12
17
|
console.warn(message, error);
|
|
13
18
|
throw new graphql_1.GraphQLError(error.message, {
|
|
@@ -16,19 +21,22 @@ function errorHandler(error, data) {
|
|
|
16
21
|
isOrionError: !!error.isOrionError,
|
|
17
22
|
isValidationError: !!error.isValidationError,
|
|
18
23
|
code: error.code,
|
|
24
|
+
hash,
|
|
19
25
|
info: error.getInfo()
|
|
20
26
|
}
|
|
21
27
|
});
|
|
22
28
|
}
|
|
23
29
|
else {
|
|
24
|
-
const hash = crypto_1.default
|
|
25
|
-
.createHash('sha1')
|
|
26
|
-
.update(error.message, 'utf8')
|
|
27
|
-
.digest('hex')
|
|
28
|
-
.substring(0, 10);
|
|
29
|
-
error.hash = hash;
|
|
30
30
|
console.error(message, error);
|
|
31
|
-
throw new
|
|
31
|
+
throw new graphql_1.GraphQLError(`${error.message} [${hash}]`, {
|
|
32
|
+
// originalError: error,
|
|
33
|
+
extensions: {
|
|
34
|
+
isOrionError: false,
|
|
35
|
+
isValidationError: false,
|
|
36
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
37
|
+
hash: hash
|
|
38
|
+
}
|
|
39
|
+
});
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
exports.default = errorHandler;
|
package/lib/startGraphQL.test.js
CHANGED
|
@@ -157,6 +157,7 @@ describe('Test GraphQL Server', () => {
|
|
|
157
157
|
extensions: {
|
|
158
158
|
isOrionError: true,
|
|
159
159
|
isValidationError: true,
|
|
160
|
+
hash: 'f3c9a8e163',
|
|
160
161
|
code: 'validationError',
|
|
161
162
|
info: {
|
|
162
163
|
error: 'validationError',
|
|
@@ -220,6 +221,7 @@ describe('Test GraphQL Server', () => {
|
|
|
220
221
|
isOrionError: true,
|
|
221
222
|
isValidationError: false,
|
|
222
223
|
code: 'code',
|
|
224
|
+
hash: '6f9b9af3cd',
|
|
223
225
|
info: {
|
|
224
226
|
error: 'code',
|
|
225
227
|
message: 'message'
|
|
@@ -232,6 +234,63 @@ describe('Test GraphQL Server', () => {
|
|
|
232
234
|
}
|
|
233
235
|
});
|
|
234
236
|
});
|
|
237
|
+
it('should return server errors correctly', async () => {
|
|
238
|
+
const resolvers = {
|
|
239
|
+
helloWorld: (0, resolvers_1.resolver)({
|
|
240
|
+
params: {
|
|
241
|
+
name: {
|
|
242
|
+
type: 'string'
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
returns: 'string',
|
|
246
|
+
async resolve({ name }) {
|
|
247
|
+
throw new Error('message');
|
|
248
|
+
return `Hello ${name}`;
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
};
|
|
252
|
+
const app = (0, http_1.express)();
|
|
253
|
+
await (0, _1.startGraphQL)({
|
|
254
|
+
resolvers,
|
|
255
|
+
app
|
|
256
|
+
});
|
|
257
|
+
const response = await (0, supertest_1.default)(app)
|
|
258
|
+
.post('/graphql')
|
|
259
|
+
.send({
|
|
260
|
+
operationName: 'testOperation',
|
|
261
|
+
variables: {
|
|
262
|
+
name: 'Nico'
|
|
263
|
+
},
|
|
264
|
+
query: `query testOperation($name: String) {
|
|
265
|
+
helloWorld(name: $name)
|
|
266
|
+
}`
|
|
267
|
+
});
|
|
268
|
+
expect(response.statusCode).toBe(200);
|
|
269
|
+
const hash = '6f9b9af3cd';
|
|
270
|
+
expect(response.body).toEqual({
|
|
271
|
+
errors: [
|
|
272
|
+
{
|
|
273
|
+
message: `message [${hash}]`,
|
|
274
|
+
locations: [
|
|
275
|
+
{
|
|
276
|
+
line: 2,
|
|
277
|
+
column: 11
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
path: ['helloWorld'],
|
|
281
|
+
extensions: {
|
|
282
|
+
isOrionError: false,
|
|
283
|
+
isValidationError: false,
|
|
284
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
285
|
+
hash: hash
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
],
|
|
289
|
+
data: {
|
|
290
|
+
helloWorld: null
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
});
|
|
235
294
|
it('Should make requests to schemas with typed models', async () => {
|
|
236
295
|
let Params = class Params {
|
|
237
296
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/graphql",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"@apollo/server": "^4.3.0",
|
|
17
17
|
"@graphql-tools/schema": "^9.0.12",
|
|
18
18
|
"@orion-js/env": "^3.5.0",
|
|
19
|
-
"@orion-js/helpers": "^3.5.
|
|
20
|
-
"@orion-js/http": "^3.5.
|
|
21
|
-
"@orion-js/models": "^3.5.
|
|
22
|
-
"@orion-js/resolvers": "^3.5.
|
|
19
|
+
"@orion-js/helpers": "^3.5.3",
|
|
20
|
+
"@orion-js/http": "^3.5.3",
|
|
21
|
+
"@orion-js/models": "^3.5.3",
|
|
22
|
+
"@orion-js/resolvers": "^3.5.3",
|
|
23
23
|
"@orion-js/schema": "^3.5.0",
|
|
24
|
-
"@orion-js/services": "^3.5.
|
|
25
|
-
"@orion-js/typed-model": "^3.5.
|
|
24
|
+
"@orion-js/services": "^3.5.3",
|
|
25
|
+
"@orion-js/typed-model": "^3.5.3",
|
|
26
26
|
"graphql-iso-date": "^3.6.1",
|
|
27
27
|
"graphql-subscriptions": "2.0.0",
|
|
28
28
|
"graphql-ws": "^5.11.2",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "34430096bb765afdc07b6f3c079915d424491b9c"
|
|
55
55
|
}
|