@envelop/testing 4.4.0-alpha-e9434aa.0 → 4.4.0-alpha-731c100.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/esm/index.js +20 -28
- package/package.json +3 -3
package/esm/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
|
-
const core_1 = require("@envelop/core");
|
|
6
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
1
|
+
import { getOperationAST, GraphQLError, print } from 'graphql';
|
|
2
|
+
import { useSchema, envelop, isAsyncIterable } from '@envelop/core';
|
|
3
|
+
import { mapSchema as cloneSchema, isDocumentNode } from '@graphql-tools/utils';
|
|
7
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
8
|
-
function createSpiedPlugin() {
|
|
5
|
+
export function createSpiedPlugin() {
|
|
9
6
|
const afterResolver = jest.fn();
|
|
10
7
|
const baseSpies = {
|
|
11
8
|
onSchemaChange: jest.fn(),
|
|
@@ -43,24 +40,23 @@ function createSpiedPlugin() {
|
|
|
43
40
|
},
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
function createTestkit(pluginsOrEnvelop, schema) {
|
|
43
|
+
export function createTestkit(pluginsOrEnvelop, schema) {
|
|
48
44
|
const toGraphQLErrorOrThrow = (thrownThing) => {
|
|
49
|
-
if (thrownThing instanceof
|
|
45
|
+
if (thrownThing instanceof GraphQLError) {
|
|
50
46
|
return thrownThing;
|
|
51
47
|
}
|
|
52
48
|
throw thrownThing;
|
|
53
49
|
};
|
|
54
50
|
const phasesReplacements = [];
|
|
55
51
|
let getEnveloped = Array.isArray(pluginsOrEnvelop)
|
|
56
|
-
?
|
|
57
|
-
plugins: [...(schema ? [
|
|
52
|
+
? envelop({
|
|
53
|
+
plugins: [...(schema ? [useSchema(cloneSchema(schema))] : []), ...pluginsOrEnvelop],
|
|
58
54
|
})
|
|
59
55
|
: pluginsOrEnvelop;
|
|
60
56
|
return {
|
|
61
57
|
modifyPlugins(modifyPluginsFn) {
|
|
62
|
-
getEnveloped =
|
|
63
|
-
plugins: [...(schema ? [
|
|
58
|
+
getEnveloped = envelop({
|
|
59
|
+
plugins: [...(schema ? [useSchema(cloneSchema(schema))] : []), ...modifyPluginsFn(getEnveloped._plugins)],
|
|
64
60
|
});
|
|
65
61
|
},
|
|
66
62
|
mockPhase(phaseReplacement) {
|
|
@@ -90,7 +86,7 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
90
86
|
}
|
|
91
87
|
let document;
|
|
92
88
|
try {
|
|
93
|
-
document =
|
|
89
|
+
document = isDocumentNode(operation) ? operation : proxy.parse(operation);
|
|
94
90
|
}
|
|
95
91
|
catch (err) {
|
|
96
92
|
return {
|
|
@@ -111,10 +107,10 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
111
107
|
errors: validationErrors,
|
|
112
108
|
};
|
|
113
109
|
}
|
|
114
|
-
const mainOperation =
|
|
110
|
+
const mainOperation = getOperationAST(document);
|
|
115
111
|
if (mainOperation == null) {
|
|
116
112
|
return {
|
|
117
|
-
errors: [new
|
|
113
|
+
errors: [new GraphQLError('Could not identify main operation.')],
|
|
118
114
|
};
|
|
119
115
|
}
|
|
120
116
|
const contextValue = await proxy.contextFactory({
|
|
@@ -123,12 +119,12 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
123
119
|
method: 'POST',
|
|
124
120
|
query: '',
|
|
125
121
|
body: {
|
|
126
|
-
query:
|
|
122
|
+
query: print(document),
|
|
127
123
|
variables: variableValues,
|
|
128
124
|
},
|
|
129
125
|
},
|
|
130
126
|
document,
|
|
131
|
-
operation:
|
|
127
|
+
operation: print(document),
|
|
132
128
|
variables: variableValues,
|
|
133
129
|
...initialContext,
|
|
134
130
|
});
|
|
@@ -151,24 +147,20 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
151
147
|
},
|
|
152
148
|
};
|
|
153
149
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if ((0, core_1.isAsyncIterable)(input)) {
|
|
150
|
+
export function assertSingleExecutionValue(input) {
|
|
151
|
+
if (isAsyncIterable(input)) {
|
|
157
152
|
throw new Error('Received stream but expected single result');
|
|
158
153
|
}
|
|
159
154
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (!(0, core_1.isAsyncIterable)(input)) {
|
|
155
|
+
export function assertStreamExecutionValue(input) {
|
|
156
|
+
if (!isAsyncIterable(input)) {
|
|
163
157
|
throw new Error('Received single result but expected stream.');
|
|
164
158
|
}
|
|
165
159
|
}
|
|
166
|
-
|
|
167
|
-
const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
160
|
+
export const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
168
161
|
const values = [];
|
|
169
162
|
for await (const value of asyncIterable) {
|
|
170
163
|
values.push(value);
|
|
171
164
|
}
|
|
172
165
|
return values;
|
|
173
166
|
};
|
|
174
|
-
exports.collectAsyncIteratorValues = collectAsyncIteratorValues;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/testing",
|
|
3
|
-
"version": "4.4.0-alpha-
|
|
3
|
+
"version": "4.4.0-alpha-731c100.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
7
|
-
"@envelop/types": "2.3.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-731c100.0",
|
|
7
|
+
"@envelop/types": "2.3.0-alpha-731c100.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|