@envelop/testing 5.0.0-alpha-36a1267.0 → 5.0.0-alpha-5b6bfa8.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.
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const graphql = require('graphql');
6
- const core = require('@envelop/core');
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 graphql.GraphQLError) {
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
- ? core.envelop({
58
- plugins: [...(schema ? [core.useSchema(utils.mapSchema(schema))] : []), ...pluginsOrEnvelop],
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 = core.envelop({
64
- plugins: [...(schema ? [core.useSchema(utils.mapSchema(schema))] : []), ...modifyPluginsFn(getEnveloped._plugins)],
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 = utils.isDocumentNode(operation) ? operation : proxy.parse(operation);
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 = graphql.getOperationAST(document);
114
+ const mainOperation = (0, graphql_1.getOperationAST)(document);
116
115
  if (mainOperation == null) {
117
116
  return {
118
- errors: [new graphql.GraphQLError('Could not identify main operation.')],
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: graphql.print(document),
126
+ query: (0, graphql_1.print)(document),
128
127
  variables: variableValues,
129
128
  },
130
129
  },
131
130
  document,
132
- operation: graphql.print(document),
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 (core.isAsyncIterable(input)) {
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 (!core.isAsyncIterable(input)) {
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;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,9 +1,8 @@
1
- import { getOperationAST, GraphQLError, print } from 'graphql';
2
- import { envelop, useSchema, isAsyncIterable } from '@envelop/core';
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(mapSchema(schema))] : []), ...pluginsOrEnvelop],
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(mapSchema(schema))] : []), ...modifyPluginsFn(getEnveloped._plugins)],
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,37 +1,59 @@
1
1
  {
2
2
  "name": "@envelop/testing",
3
- "version": "5.0.0-alpha-36a1267.0",
3
+ "version": "5.0.0-alpha-5b6bfa8.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.1.0-alpha-36a1267.0",
7
- "@envelop/types": "^2.0.0",
6
+ "@envelop/core": "3.0.0-alpha-5b6bfa8.0",
7
+ "@envelop/types": "^2.3.0",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@graphql-tools/utils": "^8.6.1"
11
+ "@graphql-tools/graphql": "0.1.0-alpha-33fb2950.0",
12
+ "@graphql-tools/utils": "8.9.1-alpha-33fb2950.0"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
15
- "url": "https://github.com/dotansimha/envelop.git",
16
+ "url": "https://github.com/n1ru4l/envelop.git",
16
17
  "directory": "packages/testing"
17
18
  },
18
19
  "author": "Dotan Simha <dotansimha@gmail.com>",
19
20
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
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
- "require": "./index.js",
29
- "import": "./index.mjs"
30
+ "require": {
31
+ "types": "./typings/index.d.ts",
32
+ "default": "./cjs/index.js"
33
+ },
34
+ "import": {
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"
41
+ }
30
42
  },
31
43
  "./*": {
32
- "require": "./*.js",
33
- "import": "./*.mjs"
44
+ "require": {
45
+ "types": "./typings/*.d.ts",
46
+ "default": "./cjs/*.js"
47
+ },
48
+ "import": {
49
+ "types": "./typings/*.d.ts",
50
+ "default": "./esm/*.js"
51
+ },
52
+ "default": {
53
+ "types": "./typings/*.d.ts",
54
+ "default": "./esm/*.js"
55
+ }
34
56
  },
35
57
  "./package.json": "./package.json"
36
58
  }
37
- }
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>[];