@envelop/apollo-server-errors 1.2.0 → 1.2.2-alpha-63e92f8.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/index.d.ts +1 -1
- package/index.js +2 -33
- package/index.mjs +1 -32
- package/package.json +5 -3
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -2,40 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
const core = require('@envelop/core');
|
|
5
6
|
const apolloServerErrors = require('apollo-server-errors');
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
9
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
10
|
-
*
|
|
11
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
12
|
-
*/
|
|
13
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
14
|
-
return (maybeAsyncIterable != null &&
|
|
15
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
16
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A utility function for hanlding `onExecuteDone` hook result, for simplifying the hanlding of AsyncIterable returned from `execute`.
|
|
20
|
-
*
|
|
21
|
-
* @param payload The payload send to `onExecuteDone` hook function
|
|
22
|
-
* @param fn The handler to be executed on each result
|
|
23
|
-
* @returns a subscription for streamed results, or undefined in case of an non-async
|
|
24
|
-
*/
|
|
25
|
-
function handleStreamOrSingleExecutionResult(payload, fn) {
|
|
26
|
-
if (isAsyncIterable(payload.result)) {
|
|
27
|
-
return { onNext: fn };
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
fn({
|
|
31
|
-
args: payload.args,
|
|
32
|
-
result: payload.result,
|
|
33
|
-
setResult: payload.setResult,
|
|
34
|
-
});
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
8
|
const makeHandleResult = (options = {}) => ({ result, setResult }) => {
|
|
40
9
|
if (result.errors && result.errors.length > 0) {
|
|
41
10
|
setResult({
|
|
@@ -57,7 +26,7 @@ const useApolloServerErrors = (options = {}) => {
|
|
|
57
26
|
const handleResult = makeHandleResult(options);
|
|
58
27
|
return {
|
|
59
28
|
onExecuteDone(payload) {
|
|
60
|
-
return handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
29
|
+
return core.handleStreamOrSingleExecutionResult(payload, handleResult);
|
|
61
30
|
},
|
|
62
31
|
};
|
|
63
32
|
},
|
package/index.mjs
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
+
import { handleStreamOrSingleExecutionResult } from '@envelop/core';
|
|
1
2
|
import { formatApolloErrors } from 'apollo-server-errors';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
5
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
6
|
-
*
|
|
7
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
8
|
-
*/
|
|
9
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
10
|
-
return (maybeAsyncIterable != null &&
|
|
11
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
12
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A utility function for hanlding `onExecuteDone` hook result, for simplifying the hanlding of AsyncIterable returned from `execute`.
|
|
16
|
-
*
|
|
17
|
-
* @param payload The payload send to `onExecuteDone` hook function
|
|
18
|
-
* @param fn The handler to be executed on each result
|
|
19
|
-
* @returns a subscription for streamed results, or undefined in case of an non-async
|
|
20
|
-
*/
|
|
21
|
-
function handleStreamOrSingleExecutionResult(payload, fn) {
|
|
22
|
-
if (isAsyncIterable(payload.result)) {
|
|
23
|
-
return { onNext: fn };
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
fn({
|
|
27
|
-
args: payload.args,
|
|
28
|
-
result: payload.result,
|
|
29
|
-
setResult: payload.setResult,
|
|
30
|
-
});
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
4
|
const makeHandleResult = (options = {}) => ({ result, setResult }) => {
|
|
36
5
|
if (result.errors && result.errors.length > 0) {
|
|
37
6
|
setResult({
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/apollo-server-errors",
|
|
3
|
-
"version": "1.2.0",
|
|
3
|
+
"version": "1.2.2-alpha-63e92f8.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
+
"@envelop/core": "1.6.6-alpha-63e92f8.0",
|
|
6
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
8
|
},
|
|
8
9
|
"dependencies": {
|
|
9
|
-
"apollo-server-errors": "3.
|
|
10
|
+
"apollo-server-errors": "3.3.0"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"./*": {
|
|
30
31
|
"require": "./*.js",
|
|
31
32
|
"import": "./*.mjs"
|
|
32
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
33
35
|
}
|
|
34
36
|
}
|