graphql-data-generator 0.4.0-alpha.1 → 0.4.0-alpha.3

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/init.js CHANGED
@@ -97,13 +97,13 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
97
97
  Object.defineProperties(obj, {
98
98
  patch: {
99
99
  value: (...patches) => {
100
- const prev = typeof obj === "function" ? obj() : obj;
101
100
  const builder = build[operation];
102
- const { result, request, error, ...rest } = prev;
101
+ const { result, request, ...rest } = typeof obj === "function"
102
+ ? obj()
103
+ : obj;
103
104
  return builder({
104
105
  data: result.data,
105
106
  variables: request.variables,
106
- error: error,
107
107
  errors: result.errors,
108
108
  ...rest,
109
109
  }, ...patches);
@@ -111,13 +111,13 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
111
111
  },
112
112
  variables: {
113
113
  value: (variables) => {
114
- const prev = typeof obj === "function" ? obj() : obj;
115
114
  const builder = build[operation];
116
- const { result, request, error, ...rest } = prev;
115
+ const { result, request, ...rest } = typeof obj === "function"
116
+ ? obj()
117
+ : obj;
117
118
  const mock = builder({
118
119
  data: result.data,
119
120
  variables: request.variables,
120
- error: error,
121
121
  errors: result.errors,
122
122
  ...rest,
123
123
  }, {
@@ -131,13 +131,13 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
131
131
  },
132
132
  data: {
133
133
  value: (data) => {
134
- const prev = typeof obj === "function" ? obj() : obj;
135
134
  const builder = build[operation];
136
- const { result, request, error, ...rest } = prev;
135
+ const { result, request, ...rest } = typeof obj === "function"
136
+ ? obj()
137
+ : obj;
137
138
  const mock = builder({
138
139
  data: result.data,
139
140
  variables: request.variables,
140
- error: error,
141
141
  errors: result.errors,
142
142
  ...rest,
143
143
  }, {
@@ -152,12 +152,14 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
152
152
  });
153
153
  Object.defineProperties(obj, Object.fromEntries(Object.entries(transforms[operation] ?? {}).map(([name, fn]) => [name, {
154
154
  value: (...args) => {
155
- const prev = typeof obj === "function" ? obj() : obj;
155
+ const { result, request, ...rest } = typeof obj === "function"
156
+ ? obj()
157
+ : obj;
156
158
  const prevInput = {
157
- data: prev.result.data,
158
- variables: prev.request.variables,
159
- error: prev.error,
160
- errors: prev.result.errors,
159
+ data: result.data,
160
+ variables: request.variables,
161
+ errors: result.errors,
162
+ ...rest,
161
163
  };
162
164
  const operationFn = fn;
163
165
  const patch = (typeof operationFn === "function"
package/esm/jest.js CHANGED
@@ -173,27 +173,11 @@ export const waitForMocks = async (mock = lastMocks.length, { timeout, offset =
173
173
  */
174
174
  export const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
175
175
  const observableMocks = useMemo(() => {
176
- const observableMocks = mocks.flatMap((m) => [
177
- typeof m.result === "function" && "mock" in m.result ? m : {
178
- ...m,
179
- stack: m.stack,
180
- result: Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
181
- },
182
- ...(m.watch
183
- ? [{
184
- ...m,
185
- stack: m.stack,
186
- result: typeof m.result === "function" && "mock" in m.result
187
- ? m.result
188
- : Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
189
- watch: false,
190
- // TODO: this might be dependent on Apollo version or refetch method,
191
- // ideally should be asserted when we can (maybe when
192
- // _failRefetchWarnings is false?)
193
- optional: true,
194
- }]
195
- : []),
196
- ]);
176
+ const observableMocks = mocks.map((m) => typeof m.result === "function" && "mock" in m.result ? m : {
177
+ ...m,
178
+ stack: m.stack,
179
+ result: Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
180
+ });
197
181
  lastMocks = observableMocks;
198
182
  afterTest.push(() => _waitForMocks(lastMocks, { cause: renderStack }));
199
183
  return observableMocks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.4.0-alpha.1",
3
+ "version": "0.4.0-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/init.js CHANGED
@@ -123,13 +123,13 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
123
123
  Object.defineProperties(obj, {
124
124
  patch: {
125
125
  value: (...patches) => {
126
- const prev = typeof obj === "function" ? obj() : obj;
127
126
  const builder = build[operation];
128
- const { result, request, error, ...rest } = prev;
127
+ const { result, request, ...rest } = typeof obj === "function"
128
+ ? obj()
129
+ : obj;
129
130
  return builder({
130
131
  data: result.data,
131
132
  variables: request.variables,
132
- error: error,
133
133
  errors: result.errors,
134
134
  ...rest,
135
135
  }, ...patches);
@@ -137,13 +137,13 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
137
137
  },
138
138
  variables: {
139
139
  value: (variables) => {
140
- const prev = typeof obj === "function" ? obj() : obj;
141
140
  const builder = build[operation];
142
- const { result, request, error, ...rest } = prev;
141
+ const { result, request, ...rest } = typeof obj === "function"
142
+ ? obj()
143
+ : obj;
143
144
  const mock = builder({
144
145
  data: result.data,
145
146
  variables: request.variables,
146
- error: error,
147
147
  errors: result.errors,
148
148
  ...rest,
149
149
  }, {
@@ -157,13 +157,13 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
157
157
  },
158
158
  data: {
159
159
  value: (data) => {
160
- const prev = typeof obj === "function" ? obj() : obj;
161
160
  const builder = build[operation];
162
- const { result, request, error, ...rest } = prev;
161
+ const { result, request, ...rest } = typeof obj === "function"
162
+ ? obj()
163
+ : obj;
163
164
  const mock = builder({
164
165
  data: result.data,
165
166
  variables: request.variables,
166
- error: error,
167
167
  errors: result.errors,
168
168
  ...rest,
169
169
  }, {
@@ -178,12 +178,14 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
178
178
  });
179
179
  Object.defineProperties(obj, Object.fromEntries(Object.entries(transforms[operation] ?? {}).map(([name, fn]) => [name, {
180
180
  value: (...args) => {
181
- const prev = typeof obj === "function" ? obj() : obj;
181
+ const { result, request, ...rest } = typeof obj === "function"
182
+ ? obj()
183
+ : obj;
182
184
  const prevInput = {
183
- data: prev.result.data,
184
- variables: prev.request.variables,
185
- error: prev.error,
186
- errors: prev.result.errors,
185
+ data: result.data,
186
+ variables: request.variables,
187
+ errors: result.errors,
188
+ ...rest,
187
189
  };
188
190
  const operationFn = fn;
189
191
  const patch = (typeof operationFn === "function"
package/script/jest.js CHANGED
@@ -203,27 +203,11 @@ exports.waitForMocks = waitForMocks;
203
203
  */
204
204
  const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
205
205
  const observableMocks = (0, react_1.useMemo)(() => {
206
- const observableMocks = mocks.flatMap((m) => [
207
- typeof m.result === "function" && "mock" in m.result ? m : {
208
- ...m,
209
- stack: m.stack,
210
- result: Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
211
- },
212
- ...(m.watch
213
- ? [{
214
- ...m,
215
- stack: m.stack,
216
- result: typeof m.result === "function" && "mock" in m.result
217
- ? m.result
218
- : Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
219
- watch: false,
220
- // TODO: this might be dependent on Apollo version or refetch method,
221
- // ideally should be asserted when we can (maybe when
222
- // _failRefetchWarnings is false?)
223
- optional: true,
224
- }]
225
- : []),
226
- ]);
206
+ const observableMocks = mocks.map((m) => typeof m.result === "function" && "mock" in m.result ? m : {
207
+ ...m,
208
+ stack: m.stack,
209
+ result: Object.assign(jest.fn((vars) => typeof m.result === "function" ? m.result(vars) : m.result), m.result),
210
+ });
227
211
  lastMocks = observableMocks;
228
212
  afterTest.push(() => _waitForMocks(lastMocks, { cause: renderStack }));
229
213
  return observableMocks;
@@ -11,7 +11,7 @@ type OperationBuilder<Data extends Record<string, unknown> = Record<string, unkn
11
11
  } & {
12
12
  [Transform in keyof Transforms]: Transforms[Transform] extends (...args: any[]) => unknown ? (...params: Shift<Parameters<Transforms[Transform]>>) => OperationBuilderWithMock<Data, Variables, Transforms, Extra> : () => OperationBuilderWithMock<Data, Variables, Transforms, Extra>;
13
13
  };
14
- type OperationBuilderWithMock<Data extends Record<string, unknown>, Variables, Transforms, Extra> = OperationBuilder<Data, Variables, Transforms> & OperationMock<Data, Variables> & Partial<Extra>;
14
+ type OperationBuilderWithMock<Data extends Record<string, unknown>, Variables, Transforms, Extra> = OperationBuilder<Data, Variables, Transforms, Extra> & OperationMock<Data, Variables> & Partial<Extra>;
15
15
  type ObjectTransforms<T, Transforms> = {
16
16
  [Transform in keyof Transforms]: Transforms[Transform] extends (...args: any[]) => any ? (...args: Shift<Parameters<Transforms[Transform]>>) => T & ObjectTransforms<T, Transforms> : () => T & ObjectTransforms<T, Transforms>;
17
17
  } & {