graphql-data-generator 0.4.0-alpha.4 → 0.4.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/README.md CHANGED
@@ -8,6 +8,7 @@ tests.
8
8
 
9
9
  - [Example](#example-setting-up-a-builder-and-building-objects)
10
10
  - [CLI options](#cli-options)
11
+ - [@graphql-codegen plugin](#graphql-codegen-plugin)
11
12
  - [Patches](#patches)
12
13
  - [Transforms](#transforms)
13
14
  - [Testing](#testing)
package/esm/cli.js CHANGED
@@ -4,7 +4,6 @@ import { readFile } from "node:fs";
4
4
  import fg from "fast-glob";
5
5
  import { parseArgs } from "node:util";
6
6
  import { codegen, loadFiles } from "./codegen.js";
7
- import { formatCode } from "./util.js";
8
7
  import process from "node:process";
9
8
  (async () => {
10
9
  const args = parseArgs({
@@ -80,14 +79,14 @@ import process from "node:process";
80
79
  banner = args.banner;
81
80
  }
82
81
  try {
83
- const file = banner + await formatCode(codegen(schema, operations, {
82
+ const file = banner + codegen(schema, operations, {
84
83
  enums: args.enums,
85
84
  includeTypenames: !args.notypenames,
86
85
  scalars,
87
86
  exports,
88
87
  typesFile: args.typesFile,
89
88
  namingConvention: args.namingConvention,
90
- }));
89
+ });
91
90
  if (args.outfile)
92
91
  await dntShim.Deno.writeTextFile(args.outfile, file);
93
92
  else
package/esm/codegen.js CHANGED
@@ -310,9 +310,9 @@ const defaultScalars = {
310
310
  Boolean: "boolean",
311
311
  ID: "string",
312
312
  };
313
- export const codegen = (schema, files, { enums = "literals", scalars, includeTypenames = true, exports = [], typesFile, namingConvention = "keep", } = {}) => {
314
- const rename = typesFile
315
- ? convertFactory({ namingConvention })
313
+ export const codegen = (schema, files, { enums = "literals", scalars, includeTypenames = true, exports = [], typesFile, namingConvention, omitOperationSuffix = !typesFile, } = {}) => {
314
+ const rename = namingConvention || typesFile
315
+ ? convertFactory({ namingConvention: namingConvention ?? "keep" })
316
316
  : (v) => v;
317
317
  const schemaDoc = parse(typeof schema === "string" ? schema : printSchema(schema));
318
318
  scalars = { ...defaultScalars, ...scalars };
@@ -436,7 +436,7 @@ export const codegen = (schema, files, { enums = "literals", scalars, includeTyp
436
436
  }
437
437
  const operationDataName = (operation, type) => {
438
438
  const name = operation.name;
439
- if (inputs[name] || types[name] || typesFile) {
439
+ if (inputs[name] || types[name] || !omitOperationSuffix) {
440
440
  return rename(`${name}${type[0].toUpperCase()}${type.slice(1)}`);
441
441
  }
442
442
  for (const key in operations) {
@@ -604,6 +604,6 @@ export const loadFiles = async (schemaPath, operationDirs) => {
604
604
  }
605
605
  return [
606
606
  await readFile(schemaPath, "utf-8"),
607
- await Promise.all(operationPromises),
607
+ (await Promise.all(operationPromises)).sort((a, b) => a.path.localeCompare(b.path)),
608
608
  ];
609
609
  };
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { init } from "./init.js";
2
2
  export { codegen } from "./codegen.js";
3
3
  export { clear, operation, proxy } from "./proxy.js";
4
- export { formatCode, toObject } from "./util.js";
4
+ export { toObject } from "./util.js";
package/esm/jest.js CHANGED
@@ -207,8 +207,8 @@ export const MockedProvider = ({ mocks, stack: renderStack, children, link: pass
207
207
  });
208
208
  return ApolloLink.from([
209
209
  errorLoggingLink,
210
- mockLink,
211
210
  ...(passedLink ? [passedLink] : []),
211
+ mockLink,
212
212
  ]);
213
213
  }, [observableMocks, renderStack]);
214
214
  if (_failRefetchWarnings) {
package/esm/plugin.cjs CHANGED
@@ -2,7 +2,6 @@
2
2
  module.exports = {
3
3
  async plugin(schema, documents, config) {
4
4
  const { codegen } = await import("./codegen.js");
5
- const { formatCode } = await import("./util.js");
6
- return (config.banner ?? "") + await formatCode(codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config }));
5
+ return (config.banner ?? "") + codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config });
7
6
  },
8
7
  };
package/esm/util.js CHANGED
@@ -1,4 +1,3 @@
1
- import { spawn } from "node:child_process";
2
1
  export const raise = (error) => {
3
2
  if (typeof error === "string") {
4
3
  const err = new Error(error);
@@ -7,38 +6,6 @@ export const raise = (error) => {
7
6
  }
8
7
  throw error;
9
8
  };
10
- export const formatCode = async (input) => {
11
- try {
12
- return await new Promise((resolve, reject) => {
13
- const process = spawn("deno", ["fmt", "-"], {
14
- stdio: ["pipe", "pipe", "pipe"],
15
- });
16
- let output = "";
17
- let errorOutput = "";
18
- process.stdout.on("data", (data) => {
19
- output += data.toString();
20
- });
21
- process.stderr.on("data", (data) => {
22
- errorOutput += data.toString();
23
- });
24
- process.on("close", (code) => {
25
- if (code !== 0 || errorOutput) {
26
- reject(new Error(errorOutput || `Process exited with code ${code}`));
27
- }
28
- else
29
- resolve(output);
30
- });
31
- process.on("error", (error) => {
32
- reject(error);
33
- });
34
- process.stdin.write(input);
35
- process.stdin?.end();
36
- });
37
- }
38
- catch {
39
- return input;
40
- }
41
- };
42
9
  export const absurd = (v) => {
43
10
  const error = new Error(`Unexpected value: ${v}`);
44
11
  Error.captureStackTrace(error, absurd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.4.0-alpha.4",
3
+ "version": "0.4.0-alpha.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/cli.js CHANGED
@@ -32,7 +32,6 @@ const node_fs_1 = require("node:fs");
32
32
  const fast_glob_1 = __importDefault(require("fast-glob"));
33
33
  const node_util_1 = require("node:util");
34
34
  const codegen_js_1 = require("./codegen.js");
35
- const util_js_1 = require("./util.js");
36
35
  const node_process_1 = __importDefault(require("node:process"));
37
36
  (async () => {
38
37
  const args = (0, node_util_1.parseArgs)({
@@ -108,14 +107,14 @@ const node_process_1 = __importDefault(require("node:process"));
108
107
  banner = args.banner;
109
108
  }
110
109
  try {
111
- const file = banner + await (0, util_js_1.formatCode)((0, codegen_js_1.codegen)(schema, operations, {
110
+ const file = banner + (0, codegen_js_1.codegen)(schema, operations, {
112
111
  enums: args.enums,
113
112
  includeTypenames: !args.notypenames,
114
113
  scalars,
115
114
  exports,
116
115
  typesFile: args.typesFile,
117
116
  namingConvention: args.namingConvention,
118
- }));
117
+ });
119
118
  if (args.outfile)
120
119
  await dntShim.Deno.writeTextFile(args.outfile, file);
121
120
  else
package/script/codegen.js CHANGED
@@ -316,9 +316,9 @@ const defaultScalars = {
316
316
  Boolean: "boolean",
317
317
  ID: "string",
318
318
  };
319
- const codegen = (schema, files, { enums = "literals", scalars, includeTypenames = true, exports = [], typesFile, namingConvention = "keep", } = {}) => {
320
- const rename = typesFile
321
- ? (0, visitor_plugin_common_1.convertFactory)({ namingConvention })
319
+ const codegen = (schema, files, { enums = "literals", scalars, includeTypenames = true, exports = [], typesFile, namingConvention, omitOperationSuffix = !typesFile, } = {}) => {
320
+ const rename = namingConvention || typesFile
321
+ ? (0, visitor_plugin_common_1.convertFactory)({ namingConvention: namingConvention ?? "keep" })
322
322
  : (v) => v;
323
323
  const schemaDoc = (0, graphql_1.parse)(typeof schema === "string" ? schema : (0, graphql_1.printSchema)(schema));
324
324
  scalars = { ...defaultScalars, ...scalars };
@@ -442,7 +442,7 @@ const codegen = (schema, files, { enums = "literals", scalars, includeTypenames
442
442
  }
443
443
  const operationDataName = (operation, type) => {
444
444
  const name = operation.name;
445
- if (inputs[name] || types[name] || typesFile) {
445
+ if (inputs[name] || types[name] || !omitOperationSuffix) {
446
446
  return rename(`${name}${type[0].toUpperCase()}${type.slice(1)}`);
447
447
  }
448
448
  for (const key in operations) {
@@ -611,7 +611,7 @@ const loadFiles = async (schemaPath, operationDirs) => {
611
611
  }
612
612
  return [
613
613
  await (0, promises_1.readFile)(schemaPath, "utf-8"),
614
- await Promise.all(operationPromises),
614
+ (await Promise.all(operationPromises)).sort((a, b) => a.path.localeCompare(b.path)),
615
615
  ];
616
616
  };
617
617
  exports.loadFiles = loadFiles;
package/script/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toObject = exports.formatCode = exports.proxy = exports.operation = exports.clear = exports.codegen = exports.init = void 0;
3
+ exports.toObject = exports.proxy = exports.operation = exports.clear = exports.codegen = exports.init = void 0;
4
4
  var init_js_1 = require("./init.js");
5
5
  Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_js_1.init; } });
6
6
  var codegen_js_1 = require("./codegen.js");
@@ -10,5 +10,4 @@ Object.defineProperty(exports, "clear", { enumerable: true, get: function () { r
10
10
  Object.defineProperty(exports, "operation", { enumerable: true, get: function () { return proxy_js_1.operation; } });
11
11
  Object.defineProperty(exports, "proxy", { enumerable: true, get: function () { return proxy_js_1.proxy; } });
12
12
  var util_js_1 = require("./util.js");
13
- Object.defineProperty(exports, "formatCode", { enumerable: true, get: function () { return util_js_1.formatCode; } });
14
13
  Object.defineProperty(exports, "toObject", { enumerable: true, get: function () { return util_js_1.toObject; } });
package/script/jest.js CHANGED
@@ -237,8 +237,8 @@ const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink,
237
237
  });
238
238
  return client_1.ApolloLink.from([
239
239
  errorLoggingLink,
240
- mockLink,
241
240
  ...(passedLink ? [passedLink] : []),
241
+ mockLink,
242
242
  ]);
243
243
  }, [observableMocks, renderStack]);
244
244
  if (_failRefetchWarnings) {
package/script/plugin.cjs CHANGED
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  module.exports = {
26
26
  async plugin(schema, documents, config) {
27
27
  const { codegen } = await Promise.resolve().then(() => __importStar(require("./codegen.js")));
28
- const { formatCode } = await Promise.resolve().then(() => __importStar(require("./util.js")));
29
- return (config.banner ?? "") + await formatCode(codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config }));
28
+ return (config.banner ?? "") + codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config });
30
29
  },
31
30
  };
package/script/util.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toObject = exports.absurd = exports.formatCode = exports.raise = void 0;
4
- const node_child_process_1 = require("node:child_process");
3
+ exports.toObject = exports.absurd = exports.raise = void 0;
5
4
  const raise = (error) => {
6
5
  if (typeof error === "string") {
7
6
  const err = new Error(error);
@@ -11,39 +10,6 @@ const raise = (error) => {
11
10
  throw error;
12
11
  };
13
12
  exports.raise = raise;
14
- const formatCode = async (input) => {
15
- try {
16
- return await new Promise((resolve, reject) => {
17
- const process = (0, node_child_process_1.spawn)("deno", ["fmt", "-"], {
18
- stdio: ["pipe", "pipe", "pipe"],
19
- });
20
- let output = "";
21
- let errorOutput = "";
22
- process.stdout.on("data", (data) => {
23
- output += data.toString();
24
- });
25
- process.stderr.on("data", (data) => {
26
- errorOutput += data.toString();
27
- });
28
- process.on("close", (code) => {
29
- if (code !== 0 || errorOutput) {
30
- reject(new Error(errorOutput || `Process exited with code ${code}`));
31
- }
32
- else
33
- resolve(output);
34
- });
35
- process.on("error", (error) => {
36
- reject(error);
37
- });
38
- process.stdin.write(input);
39
- process.stdin?.end();
40
- });
41
- }
42
- catch {
43
- return input;
44
- }
45
- };
46
- exports.formatCode = formatCode;
47
13
  const absurd = (v) => {
48
14
  const error = new Error(`Unexpected value: ${v}`);
49
15
  Error.captureStackTrace(error, exports.absurd);
@@ -3,13 +3,14 @@ import { type NamingConvention } from "@graphql-codegen/visitor-plugin-common";
3
3
  export declare const codegen: (schema: GraphQLSchema | string, files: {
4
4
  path: string;
5
5
  content: string;
6
- }[], { enums, scalars, includeTypenames, exports, typesFile, namingConvention, }?: {
6
+ }[], { enums, scalars, includeTypenames, exports, typesFile, namingConvention, omitOperationSuffix, }?: {
7
7
  enums?: string;
8
8
  scalars?: Record<string, string | undefined>;
9
9
  includeTypenames?: boolean;
10
10
  exports?: ("types" | "operations")[];
11
11
  typesFile?: string;
12
12
  namingConvention?: NamingConvention;
13
+ omitOperationSuffix?: boolean;
13
14
  }) => string;
14
15
  export declare const loadFiles: (schemaPath: string, operationDirs: string[]) => Promise<[schema: string, operations: {
15
16
  path: string;
package/types/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { init } from "./init.js";
2
2
  export type { DeepPartial, OperationMock, Patch } from "./types.js";
3
3
  export { codegen } from "./codegen.js";
4
4
  export { clear, operation, proxy } from "./proxy.js";
5
- export { formatCode, toObject } from "./util.js";
5
+ export { toObject } from "./util.js";
package/types/jest.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { MockedProviderProps, MockedResponse } from "@apollo/client/testing";
3
3
  import "@testing-library/react/dont-cleanup-after-each";
4
- type ExtendedMockedResponse = MockedResponse & {
4
+ export type ExtendedMockedResponse = MockedResponse & {
5
5
  stack?: string;
6
6
  watch?: boolean;
7
7
  optional?: boolean;
@@ -49,4 +49,3 @@ export declare const MockedProvider: ({ mocks, stack: renderStack, children, lin
49
49
  mocks: ReadonlyArray<ExtendedMockedResponse>;
50
50
  stack?: string;
51
51
  }) => React.JSX.Element;
52
- export {};
package/types/util.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export declare const raise: (error: Error | string) => never;
2
- export declare const formatCode: (input: string) => Promise<string>;
3
2
  export declare const absurd: (v: never) => never;
4
3
  type StripFunctions<T> = {
5
4
  [K in keyof T]: T[K] extends (...args: any[]) => any ? never : T[K] extends object ? StripFunctions<T[K]> : T[K];