graphql-data-generator 0.3.0-alpha.13 → 0.3.0-alpha.15

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
@@ -5,16 +5,16 @@ import { Kind, parse } from "graphql";
5
5
  import { gqlPluckFromCodeStringSync } from "@graphql-tools/graphql-tag-pluck";
6
6
  import { operation, proxy, withGetDefaultPatch } from "./proxy.js";
7
7
  import { toObject } from "./util.js";
8
- import { dirname } from "node:path";
8
+ import { dirname, isAbsolute, resolve } from "node:path";
9
9
  globalThis.require ??= createRequire(dntShim.Deno.cwd());
10
10
  const files = {};
11
11
  const loadFile = (path) => {
12
12
  if (files[path])
13
13
  return files[path];
14
14
  const raw = files[path] = readFileSync(path, "utf-8");
15
- const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve(importPath, {
16
- paths: [dirname(path), dntShim.Deno.cwd()],
17
- })));
15
+ const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve(isAbsolute(importPath)
16
+ ? importPath
17
+ : resolve(dntShim.Deno.cwd(), dirname(path), importPath), { paths: [dntShim.Deno.cwd()] })));
18
18
  if (!imports.length)
19
19
  return raw;
20
20
  return [raw, ...imports].join("\n\n");
package/esm/jest.js CHANGED
@@ -2,7 +2,7 @@ import * as dntShim from "./_dnt.shims.js";
2
2
  import React, { useMemo } from "react";
3
3
  import { ApolloLink, useApolloClient, } from "@apollo/client";
4
4
  import { onError } from "@apollo/client/link/error";
5
- import { MockedProvider, MockLink, } from "@apollo/client/testing";
5
+ import { MockedProvider as ApolloMockedProvider, MockLink, } from "@apollo/client/testing";
6
6
  import { waitFor } from "@testing-library/dom";
7
7
  import { Kind, print } from "graphql";
8
8
  import { diff as jestDiff } from "jest-diff";
@@ -140,7 +140,7 @@ export const waitForMocks = async (mock = lastMocks.length, offset = 0) => {
140
140
  * requests have matching mocks and all defined mocks are used unless marked
141
141
  * `optional`.
142
142
  */
143
- export const MockProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
143
+ export const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
144
144
  const observableMocks = useMemo(() => {
145
145
  const observableMocks = mocks.flatMap((m) => [
146
146
  {
@@ -166,7 +166,7 @@ export const MockProvider = ({ mocks, stack: renderStack, children, link: passed
166
166
  mockLink.showWarnings = false;
167
167
  const errorLoggingLink = onError(({ networkError, operation }) => {
168
168
  if (_allowMissingMocks ||
169
- !networkError?.message.includes("No more mocked responses"))
169
+ !networkError?.message?.includes("No more mocked responses"))
170
170
  return;
171
171
  const { message, stack: altStack } = getErrorMessage(operation, mockLink);
172
172
  try {
@@ -208,7 +208,7 @@ export const MockProvider = ({ mocks, stack: renderStack, children, link: passed
208
208
  console.warn = oldWarn;
209
209
  });
210
210
  }
211
- return (React.createElement(MockedProvider, { ...rest, link: link },
211
+ return (React.createElement(ApolloMockedProvider, { ...rest, link: link },
212
212
  React.createElement(React.Fragment, null,
213
213
  React.createElement(AutoWatch, { mocks: observableMocks }),
214
214
  children)));
package/esm/proxy.js CHANGED
@@ -131,7 +131,7 @@ const resolveConcreteType = (definitions, definition, patch, prev) => {
131
131
  };
132
132
  const resolveValue = (definitions, scalars, type, ctx) => {
133
133
  if (type.kind !== Kind.NON_NULL_TYPE)
134
- return null;
134
+ return ctx.input ? undefined : null;
135
135
  if (type.type.kind === Kind.LIST_TYPE)
136
136
  return [];
137
137
  type = type.type;
@@ -373,6 +373,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
373
373
  selectionSet: selectionSet
374
374
  ? getSelectionSetSelection(definitions, selectionSet, prop)
375
375
  : undefined,
376
+ input: definition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION,
376
377
  });
377
378
  };
378
379
  const keys = [
@@ -466,7 +467,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
466
467
  mock.variables[name] = mockPrev.variables[name];
467
468
  continue;
468
469
  }
469
- const result = resolveValue(definitions, scalars, variableDefinition.type, { hostType: `${path}Variables`, prop: name });
470
+ const result = resolveValue(definitions, scalars, variableDefinition.type, { hostType: `${path}Variables`, prop: name, input: false });
470
471
  if (result != null) {
471
472
  if (!mock.variables)
472
473
  mock.variables = {};
@@ -534,6 +535,14 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
534
535
  const value = typeof scalar === "function" ? scalar(parent) : scalar;
535
536
  return value;
536
537
  }
538
+ case Kind.ENUM_TYPE_DEFINITION: {
539
+ const patch = patches[patches.length - 1];
540
+ if (patch != null)
541
+ return patch;
542
+ if (prev != null)
543
+ return prev;
544
+ return definition.values?.[0]?.name.value;
545
+ }
537
546
  default:
538
547
  throw new Error(`Unhandled definition kind '${definition.kind}'`);
539
548
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.3.0-alpha.13",
3
+ "version": "0.3.0-alpha.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/init.js CHANGED
@@ -38,9 +38,9 @@ const loadFile = (path) => {
38
38
  if (files[path])
39
39
  return files[path];
40
40
  const raw = files[path] = (0, node_fs_1.readFileSync)(path, "utf-8");
41
- const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve(importPath, {
42
- paths: [(0, node_path_1.dirname)(path), dntShim.Deno.cwd()],
43
- })));
41
+ const imports = Array.from(raw.matchAll(/#import "(.*)"/gm), ([, importPath]) => loadFile(require.resolve((0, node_path_1.isAbsolute)(importPath)
42
+ ? importPath
43
+ : (0, node_path_1.resolve)(dntShim.Deno.cwd(), (0, node_path_1.dirname)(path), importPath), { paths: [dntShim.Deno.cwd()] })));
44
44
  if (!imports.length)
45
45
  return raw;
46
46
  return [raw, ...imports].join("\n\n");
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.waitForMocks = exports.allowMissingMocks = exports.failRefetchWarnings = void 0;
26
+ exports.MockedProvider = exports.waitForMocks = 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");
@@ -169,7 +169,7 @@ exports.waitForMocks = waitForMocks;
169
169
  * requests have matching mocks and all defined mocks are used unless marked
170
170
  * `optional`.
171
171
  */
172
- const MockProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
172
+ const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink, ...rest }) => {
173
173
  const observableMocks = (0, react_1.useMemo)(() => {
174
174
  const observableMocks = mocks.flatMap((m) => [
175
175
  {
@@ -195,7 +195,7 @@ const MockProvider = ({ mocks, stack: renderStack, children, link: passedLink, .
195
195
  mockLink.showWarnings = false;
196
196
  const errorLoggingLink = (0, error_1.onError)(({ networkError, operation }) => {
197
197
  if (_allowMissingMocks ||
198
- !networkError?.message.includes("No more mocked responses"))
198
+ !networkError?.message?.includes("No more mocked responses"))
199
199
  return;
200
200
  const { message, stack: altStack } = getErrorMessage(operation, mockLink);
201
201
  try {
@@ -242,4 +242,4 @@ const MockProvider = ({ mocks, stack: renderStack, children, link: passedLink, .
242
242
  react_1.default.createElement(AutoWatch, { mocks: observableMocks }),
243
243
  children)));
244
244
  };
245
- exports.MockProvider = MockProvider;
245
+ exports.MockedProvider = MockedProvider;
package/script/proxy.js CHANGED
@@ -135,7 +135,7 @@ const resolveConcreteType = (definitions, definition, patch, prev) => {
135
135
  };
136
136
  const resolveValue = (definitions, scalars, type, ctx) => {
137
137
  if (type.kind !== graphql_1.Kind.NON_NULL_TYPE)
138
- return null;
138
+ return ctx.input ? undefined : null;
139
139
  if (type.type.kind === graphql_1.Kind.LIST_TYPE)
140
140
  return [];
141
141
  type = type.type;
@@ -377,6 +377,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
377
377
  selectionSet: selectionSet
378
378
  ? getSelectionSetSelection(definitions, selectionSet, prop)
379
379
  : undefined,
380
+ input: definition.kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
380
381
  });
381
382
  };
382
383
  const keys = [
@@ -470,7 +471,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
470
471
  mock.variables[name] = mockPrev.variables[name];
471
472
  continue;
472
473
  }
473
- const result = resolveValue(definitions, scalars, variableDefinition.type, { hostType: `${path}Variables`, prop: name });
474
+ const result = resolveValue(definitions, scalars, variableDefinition.type, { hostType: `${path}Variables`, prop: name, input: false });
474
475
  if (result != null) {
475
476
  if (!mock.variables)
476
477
  mock.variables = {};
@@ -538,6 +539,14 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
538
539
  const value = typeof scalar === "function" ? scalar(parent) : scalar;
539
540
  return value;
540
541
  }
542
+ case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
543
+ const patch = patches[patches.length - 1];
544
+ if (patch != null)
545
+ return patch;
546
+ if (prev != null)
547
+ return prev;
548
+ return definition.values?.[0]?.name.value;
549
+ }
541
550
  default:
542
551
  throw new Error(`Unhandled definition kind '${definition.kind}'`);
543
552
  }
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { init } from "./init.js";
2
- export type { DeepPartial, Patch } from "./types.js";
2
+ export type { DeepPartial, OperationMock, Patch } from "./types.js";
3
3
  export { codegen } from "./codegen.js";
4
4
  export { proxy } from "./proxy.js";
5
5
  export { formatCode, toObject } from "./util.js";
package/types/jest.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare const waitForMocks: (mock?: number | string, offset?: number) =>
27
27
  * requests have matching mocks and all defined mocks are used unless marked
28
28
  * `optional`.
29
29
  */
30
- export declare const MockProvider: ({ mocks, stack: renderStack, children, link: passedLink, ...rest }: Omit<MockedProviderProps, "mocks"> & {
31
- mocks: OperationMock[];
30
+ export declare const MockedProvider: ({ mocks, stack: renderStack, children, link: passedLink, ...rest }: Omit<MockedProviderProps, "mocks"> & {
31
+ mocks: ReadonlyArray<OperationMock>;
32
32
  stack?: string;
33
33
  }) => React.JSX.Element;