graphql-data-generator 0.3.0-alpha.5 → 0.3.0-alpha.6

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/jest.js CHANGED
@@ -59,9 +59,18 @@ let _failRefetchWarnings = false;
59
59
  * In older versions of `@apollo/client`, refetches with missing mocks trigger
60
60
  * warnings instead of being treated as standard missing mocks.
61
61
  * This utility converts those warnings into failures and ensures watch queries
62
- * are installed for queries with `watch: true`.
62
+ * are installed for queries with `watch: true`. This must be set when
63
+ * `MockProvider` is mounted.
64
+ *
65
+ * This is not required on modern version of `@apollo/client`.
63
66
  */
64
67
  export const failRefetchWarnings = (value = true) => _failRefetchWarnings = value;
68
+ let _allowMissingMocks = false;
69
+ /**
70
+ * Allows missing mocks, resulting in tests passing. Usage is intended to ease
71
+ * migration.
72
+ */
73
+ export const allowMissingMocks = (value) => _allowMissingMocks = value;
65
74
  const AutoWatch = ({ mocks }) => {
66
75
  const client = useApolloClient();
67
76
  for (const mock of mocks)
@@ -69,6 +78,11 @@ const AutoWatch = ({ mocks }) => {
69
78
  client.watchQuery(mock.request);
70
79
  return null;
71
80
  };
81
+ /**
82
+ * A wrapper for `@apollo/client/testing`, this component will assert all
83
+ * requests have matching mocks and all defined mocks are used unless marked
84
+ * `optional`.
85
+ */
72
86
  export const MockProvider = ({ mocks, stack: renderStack, children }) => {
73
87
  const observableMocks = useMemo(() => {
74
88
  const observableMocks = mocks.flatMap((m) => [
@@ -115,7 +129,8 @@ export const MockProvider = ({ mocks, stack: renderStack, children }) => {
115
129
  const mockLink = new MockLink(observableMocks);
116
130
  mockLink.showWarnings = false;
117
131
  const errorLoggingLink = new ErrorLink(({ networkError, operation }) => {
118
- if (!networkError?.message.includes("No more mocked responses"))
132
+ if (_allowMissingMocks ||
133
+ !networkError?.message.includes("No more mocked responses"))
119
134
  return;
120
135
  const { message, stack: altStack } = getErrorMessage(operation, mockLink);
121
136
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.3.0-alpha.5",
3
+ "version": "0.3.0-alpha.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/jest.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.MockProvider = exports.failRefetchWarnings = void 0;
26
+ exports.MockProvider = exports.allowMissingMocks = exports.failRefetchWarnings = void 0;
27
27
  const dntShim = __importStar(require("./_dnt.shims.js"));
28
28
  const react_1 = __importStar(require("react"));
29
29
  const client_1 = require("@apollo/client");
@@ -85,10 +85,20 @@ let _failRefetchWarnings = false;
85
85
  * In older versions of `@apollo/client`, refetches with missing mocks trigger
86
86
  * warnings instead of being treated as standard missing mocks.
87
87
  * This utility converts those warnings into failures and ensures watch queries
88
- * are installed for queries with `watch: true`.
88
+ * are installed for queries with `watch: true`. This must be set when
89
+ * `MockProvider` is mounted.
90
+ *
91
+ * This is not required on modern version of `@apollo/client`.
89
92
  */
90
93
  const failRefetchWarnings = (value = true) => _failRefetchWarnings = value;
91
94
  exports.failRefetchWarnings = failRefetchWarnings;
95
+ let _allowMissingMocks = false;
96
+ /**
97
+ * Allows missing mocks, resulting in tests passing. Usage is intended to ease
98
+ * migration.
99
+ */
100
+ const allowMissingMocks = (value) => _allowMissingMocks = value;
101
+ exports.allowMissingMocks = allowMissingMocks;
92
102
  const AutoWatch = ({ mocks }) => {
93
103
  const client = (0, client_1.useApolloClient)();
94
104
  for (const mock of mocks)
@@ -96,6 +106,11 @@ const AutoWatch = ({ mocks }) => {
96
106
  client.watchQuery(mock.request);
97
107
  return null;
98
108
  };
109
+ /**
110
+ * A wrapper for `@apollo/client/testing`, this component will assert all
111
+ * requests have matching mocks and all defined mocks are used unless marked
112
+ * `optional`.
113
+ */
99
114
  const MockProvider = ({ mocks, stack: renderStack, children }) => {
100
115
  const observableMocks = (0, react_1.useMemo)(() => {
101
116
  const observableMocks = mocks.flatMap((m) => [
@@ -142,7 +157,8 @@ const MockProvider = ({ mocks, stack: renderStack, children }) => {
142
157
  const mockLink = new testing_1.MockLink(observableMocks);
143
158
  mockLink.showWarnings = false;
144
159
  const errorLoggingLink = new error_1.ErrorLink(({ networkError, operation }) => {
145
- if (!networkError?.message.includes("No more mocked responses"))
160
+ if (_allowMissingMocks ||
161
+ !networkError?.message.includes("No more mocked responses"))
146
162
  return;
147
163
  const { message, stack: altStack } = getErrorMessage(operation, mockLink);
148
164
  try {
package/types/jest.d.ts CHANGED
@@ -4,9 +4,22 @@ import type { OperationMock } from "./types.js";
4
4
  * In older versions of `@apollo/client`, refetches with missing mocks trigger
5
5
  * warnings instead of being treated as standard missing mocks.
6
6
  * This utility converts those warnings into failures and ensures watch queries
7
- * are installed for queries with `watch: true`.
7
+ * are installed for queries with `watch: true`. This must be set when
8
+ * `MockProvider` is mounted.
9
+ *
10
+ * This is not required on modern version of `@apollo/client`.
8
11
  */
9
12
  export declare const failRefetchWarnings: (value?: boolean) => boolean;
13
+ /**
14
+ * Allows missing mocks, resulting in tests passing. Usage is intended to ease
15
+ * migration.
16
+ */
17
+ export declare const allowMissingMocks: (value: true) => true;
18
+ /**
19
+ * A wrapper for `@apollo/client/testing`, this component will assert all
20
+ * requests have matching mocks and all defined mocks are used unless marked
21
+ * `optional`.
22
+ */
10
23
  export declare const MockProvider: ({ mocks, stack: renderStack, children }: {
11
24
  mocks: OperationMock[];
12
25
  stack?: string;
package/types/types.d.ts CHANGED
@@ -29,12 +29,15 @@ export type OperationMock<Data extends Record<string, unknown> = Record<string,
29
29
  error?: Error;
30
30
  stack?: string;
31
31
  watch?: boolean;
32
+ optional?: boolean;
32
33
  };
33
34
  export type SimpleOperationMock<Data extends Record<string, unknown> = Record<string, unknown>, Variables = Record<string, unknown> | never> = {
34
35
  data: Data;
35
36
  variables?: Variables;
36
37
  error?: Error;
37
38
  errors?: GraphQLError[];
39
+ watch?: boolean;
40
+ optional?: boolean;
38
41
  };
39
42
  export type SimpleOperationPatch<Data extends Record<string, unknown> = Record<string, unknown>, Variables = Record<string, unknown> | never> = Patch<{
40
43
  data: Data;
@@ -42,5 +45,7 @@ export type SimpleOperationPatch<Data extends Record<string, unknown> = Record<s
42
45
  }> & {
43
46
  error?: Error;
44
47
  errors?: GraphQLError[];
48
+ watch?: boolean;
49
+ optional?: boolean;
45
50
  };
46
51
  export {};