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

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
  {
@@ -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
@@ -534,6 +534,14 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
534
534
  const value = typeof scalar === "function" ? scalar(parent) : scalar;
535
535
  return value;
536
536
  }
537
+ case Kind.ENUM_TYPE_DEFINITION: {
538
+ const patch = patches[patches.length - 1];
539
+ if (patch != null)
540
+ return patch;
541
+ if (prev != null)
542
+ return prev;
543
+ return definition.values?.[0]?.name.value;
544
+ }
537
545
  default:
538
546
  throw new Error(`Unhandled definition kind '${definition.kind}'`);
539
547
  }
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.14",
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
  {
@@ -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
@@ -538,6 +538,14 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
538
538
  const value = typeof scalar === "function" ? scalar(parent) : scalar;
539
539
  return value;
540
540
  }
541
+ case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
542
+ const patch = patches[patches.length - 1];
543
+ if (patch != null)
544
+ return patch;
545
+ if (prev != null)
546
+ return prev;
547
+ return definition.values?.[0]?.name.value;
548
+ }
541
549
  default:
542
550
  throw new Error(`Unhandled definition kind '${definition.kind}'`);
543
551
  }
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;