@envelop/testing 5.0.0-alpha-d0d0776.0 → 5.0.0-alpha-ccec0fc.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.js → cjs/index.js} +22 -25
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +10 -13
- package/package.json +27 -17
- package/{index.d.ts → typings/index.d.ts} +1 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const utils = require('@graphql-tools/utils');
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectAsyncIteratorValues = exports.assertStreamExecutionValue = exports.assertSingleExecutionValue = exports.createTestkit = exports.createSpiedPlugin = void 0;
|
|
4
|
+
const graphql_1 = require("@graphql-tools/graphql");
|
|
5
|
+
const core_1 = require("@envelop/core");
|
|
6
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
9
7
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
10
8
|
function createSpiedPlugin() {
|
|
11
9
|
const afterResolver = jest.fn();
|
|
@@ -45,23 +43,24 @@ function createSpiedPlugin() {
|
|
|
45
43
|
},
|
|
46
44
|
};
|
|
47
45
|
}
|
|
46
|
+
exports.createSpiedPlugin = createSpiedPlugin;
|
|
48
47
|
function createTestkit(pluginsOrEnvelop, schema) {
|
|
49
48
|
const toGraphQLErrorOrThrow = (thrownThing) => {
|
|
50
|
-
if (thrownThing instanceof
|
|
49
|
+
if (thrownThing instanceof graphql_1.GraphQLError) {
|
|
51
50
|
return thrownThing;
|
|
52
51
|
}
|
|
53
52
|
throw thrownThing;
|
|
54
53
|
};
|
|
55
54
|
const phasesReplacements = [];
|
|
56
55
|
let getEnveloped = Array.isArray(pluginsOrEnvelop)
|
|
57
|
-
?
|
|
58
|
-
plugins: [...(schema ? [
|
|
56
|
+
? (0, core_1.envelop)({
|
|
57
|
+
plugins: [...(schema ? [(0, core_1.useSchema)((0, utils_1.mapSchema)(schema))] : []), ...pluginsOrEnvelop],
|
|
59
58
|
})
|
|
60
59
|
: pluginsOrEnvelop;
|
|
61
60
|
return {
|
|
62
61
|
modifyPlugins(modifyPluginsFn) {
|
|
63
|
-
getEnveloped =
|
|
64
|
-
plugins: [...(schema ? [
|
|
62
|
+
getEnveloped = (0, core_1.envelop)({
|
|
63
|
+
plugins: [...(schema ? [(0, core_1.useSchema)((0, utils_1.mapSchema)(schema))] : []), ...modifyPluginsFn(getEnveloped._plugins)],
|
|
65
64
|
});
|
|
66
65
|
},
|
|
67
66
|
mockPhase(phaseReplacement) {
|
|
@@ -91,7 +90,7 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
91
90
|
}
|
|
92
91
|
let document;
|
|
93
92
|
try {
|
|
94
|
-
document =
|
|
93
|
+
document = (0, utils_1.isDocumentNode)(operation) ? operation : proxy.parse(operation);
|
|
95
94
|
}
|
|
96
95
|
catch (err) {
|
|
97
96
|
return {
|
|
@@ -112,10 +111,10 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
112
111
|
errors: validationErrors,
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
|
-
const mainOperation =
|
|
114
|
+
const mainOperation = (0, graphql_1.getOperationAST)(document);
|
|
116
115
|
if (mainOperation == null) {
|
|
117
116
|
return {
|
|
118
|
-
errors: [new
|
|
117
|
+
errors: [new graphql_1.GraphQLError('Could not identify main operation.')],
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
const contextValue = await proxy.contextFactory({
|
|
@@ -124,12 +123,12 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
124
123
|
method: 'POST',
|
|
125
124
|
query: '',
|
|
126
125
|
body: {
|
|
127
|
-
query:
|
|
126
|
+
query: (0, graphql_1.print)(document),
|
|
128
127
|
variables: variableValues,
|
|
129
128
|
},
|
|
130
129
|
},
|
|
131
130
|
document,
|
|
132
|
-
operation:
|
|
131
|
+
operation: (0, graphql_1.print)(document),
|
|
133
132
|
variables: variableValues,
|
|
134
133
|
...initialContext,
|
|
135
134
|
});
|
|
@@ -152,16 +151,19 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
152
151
|
},
|
|
153
152
|
};
|
|
154
153
|
}
|
|
154
|
+
exports.createTestkit = createTestkit;
|
|
155
155
|
function assertSingleExecutionValue(input) {
|
|
156
|
-
if (
|
|
156
|
+
if ((0, core_1.isAsyncIterable)(input)) {
|
|
157
157
|
throw new Error('Received stream but expected single result');
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
exports.assertSingleExecutionValue = assertSingleExecutionValue;
|
|
160
161
|
function assertStreamExecutionValue(input) {
|
|
161
|
-
if (!
|
|
162
|
+
if (!(0, core_1.isAsyncIterable)(input)) {
|
|
162
163
|
throw new Error('Received single result but expected stream.');
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
exports.assertStreamExecutionValue = assertStreamExecutionValue;
|
|
165
167
|
const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
166
168
|
const values = [];
|
|
167
169
|
for await (const value of asyncIterable) {
|
|
@@ -169,9 +171,4 @@ const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
|
169
171
|
}
|
|
170
172
|
return values;
|
|
171
173
|
};
|
|
172
|
-
|
|
173
|
-
exports.assertSingleExecutionValue = assertSingleExecutionValue;
|
|
174
|
-
exports.assertStreamExecutionValue = assertStreamExecutionValue;
|
|
175
174
|
exports.collectAsyncIteratorValues = collectAsyncIteratorValues;
|
|
176
|
-
exports.createSpiedPlugin = createSpiedPlugin;
|
|
177
|
-
exports.createTestkit = createTestkit;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getOperationAST, GraphQLError, print } from 'graphql';
|
|
2
|
-
import {
|
|
3
|
-
import { mapSchema, isDocumentNode } from '@graphql-tools/utils';
|
|
4
|
-
|
|
1
|
+
import { getOperationAST, GraphQLError, print, } from '@graphql-tools/graphql';
|
|
2
|
+
import { useSchema, envelop, isAsyncIterable } from '@envelop/core';
|
|
3
|
+
import { mapSchema as cloneSchema, isDocumentNode } from '@graphql-tools/utils';
|
|
5
4
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
6
|
-
function createSpiedPlugin() {
|
|
5
|
+
export function createSpiedPlugin() {
|
|
7
6
|
const afterResolver = jest.fn();
|
|
8
7
|
const baseSpies = {
|
|
9
8
|
onSchemaChange: jest.fn(),
|
|
@@ -41,7 +40,7 @@ function createSpiedPlugin() {
|
|
|
41
40
|
},
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
function createTestkit(pluginsOrEnvelop, schema) {
|
|
43
|
+
export function createTestkit(pluginsOrEnvelop, schema) {
|
|
45
44
|
const toGraphQLErrorOrThrow = (thrownThing) => {
|
|
46
45
|
if (thrownThing instanceof GraphQLError) {
|
|
47
46
|
return thrownThing;
|
|
@@ -51,13 +50,13 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
51
50
|
const phasesReplacements = [];
|
|
52
51
|
let getEnveloped = Array.isArray(pluginsOrEnvelop)
|
|
53
52
|
? envelop({
|
|
54
|
-
plugins: [...(schema ? [useSchema(
|
|
53
|
+
plugins: [...(schema ? [useSchema(cloneSchema(schema))] : []), ...pluginsOrEnvelop],
|
|
55
54
|
})
|
|
56
55
|
: pluginsOrEnvelop;
|
|
57
56
|
return {
|
|
58
57
|
modifyPlugins(modifyPluginsFn) {
|
|
59
58
|
getEnveloped = envelop({
|
|
60
|
-
plugins: [...(schema ? [useSchema(
|
|
59
|
+
plugins: [...(schema ? [useSchema(cloneSchema(schema))] : []), ...modifyPluginsFn(getEnveloped._plugins)],
|
|
61
60
|
});
|
|
62
61
|
},
|
|
63
62
|
mockPhase(phaseReplacement) {
|
|
@@ -148,22 +147,20 @@ function createTestkit(pluginsOrEnvelop, schema) {
|
|
|
148
147
|
},
|
|
149
148
|
};
|
|
150
149
|
}
|
|
151
|
-
function assertSingleExecutionValue(input) {
|
|
150
|
+
export function assertSingleExecutionValue(input) {
|
|
152
151
|
if (isAsyncIterable(input)) {
|
|
153
152
|
throw new Error('Received stream but expected single result');
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
|
-
function assertStreamExecutionValue(input) {
|
|
155
|
+
export function assertStreamExecutionValue(input) {
|
|
157
156
|
if (!isAsyncIterable(input)) {
|
|
158
157
|
throw new Error('Received single result but expected stream.');
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
|
-
const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
160
|
+
export const collectAsyncIteratorValues = async (asyncIterable) => {
|
|
162
161
|
const values = [];
|
|
163
162
|
for await (const value of asyncIterable) {
|
|
164
163
|
values.push(value);
|
|
165
164
|
}
|
|
166
165
|
return values;
|
|
167
166
|
};
|
|
168
|
-
|
|
169
|
-
export { assertSingleExecutionValue, assertStreamExecutionValue, collectAsyncIteratorValues, createSpiedPlugin, createTestkit };
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/testing",
|
|
3
|
-
"version": "5.0.0-alpha-
|
|
3
|
+
"version": "5.0.0-alpha-ccec0fc.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "3.0.0-alpha-
|
|
7
|
-
"@envelop/types": "3.0.0-alpha-
|
|
6
|
+
"@envelop/core": "3.0.0-alpha-ccec0fc.0",
|
|
7
|
+
"@envelop/types": "3.0.0-alpha-ccec0fc.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@graphql-tools/
|
|
11
|
+
"@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0",
|
|
12
|
+
"@graphql-tools/utils": "8.9.1-alpha-e7752ba5.0"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -17,33 +18,42 @@
|
|
|
17
18
|
},
|
|
18
19
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
19
20
|
"license": "MIT",
|
|
20
|
-
"main": "index.js",
|
|
21
|
-
"module": "index.
|
|
22
|
-
"typings": "index.d.ts",
|
|
21
|
+
"main": "cjs/index.js",
|
|
22
|
+
"module": "esm/index.js",
|
|
23
|
+
"typings": "typings/index.d.ts",
|
|
23
24
|
"typescript": {
|
|
24
|
-
"definition": "index.d.ts"
|
|
25
|
+
"definition": "typings/index.d.ts"
|
|
25
26
|
},
|
|
27
|
+
"type": "module",
|
|
26
28
|
"exports": {
|
|
27
29
|
".": {
|
|
28
30
|
"require": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
+
"types": "./typings/index.d.ts",
|
|
32
|
+
"default": "./cjs/index.js"
|
|
31
33
|
},
|
|
32
34
|
"import": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
+
"types": "./typings/index.d.ts",
|
|
36
|
+
"default": "./esm/index.js"
|
|
37
|
+
},
|
|
38
|
+
"default": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
35
41
|
}
|
|
36
42
|
},
|
|
37
43
|
"./*": {
|
|
38
44
|
"require": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
45
|
+
"types": "./typings/*.d.ts",
|
|
46
|
+
"default": "./cjs/*.js"
|
|
41
47
|
},
|
|
42
48
|
"import": {
|
|
43
|
-
"
|
|
44
|
-
"
|
|
49
|
+
"types": "./typings/*.d.ts",
|
|
50
|
+
"default": "./esm/*.js"
|
|
51
|
+
},
|
|
52
|
+
"default": {
|
|
53
|
+
"types": "./typings/*.d.ts",
|
|
54
|
+
"default": "./esm/*.js"
|
|
45
55
|
}
|
|
46
56
|
},
|
|
47
57
|
"./package.json": "./package.json"
|
|
48
58
|
}
|
|
49
|
-
}
|
|
59
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="jest" />
|
|
2
|
-
import { DocumentNode, ExecutionResult, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { DocumentNode, ExecutionResult, GraphQLSchema } from '@graphql-tools/graphql';
|
|
3
3
|
import { PluginOrDisabledPlugin } from '@envelop/core';
|
|
4
4
|
import { GetEnvelopedFn, Plugin } from '@envelop/types';
|
|
5
5
|
export declare type ModifyPluginsFn = (plugins: Plugin<any>[]) => Plugin<any>[];
|