protoc-gen-pothos 0.3.2 → 0.3.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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -1
  3. package/package.json +16 -10
  4. package/lib/dslgen/index.d.ts +0 -2
  5. package/lib/dslgen/index.d.ts.map +0 -1
  6. package/lib/dslgen/index.js +0 -17
  7. package/lib/dslgen/printers/enumType.d.ts +0 -16
  8. package/lib/dslgen/printers/enumType.d.ts.map +0 -1
  9. package/lib/dslgen/printers/enumType.js +0 -40
  10. package/lib/dslgen/printers/field.d.ts +0 -41
  11. package/lib/dslgen/printers/field.d.ts.map +0 -1
  12. package/lib/dslgen/printers/field.js +0 -99
  13. package/lib/dslgen/printers/fieldResolver/enumFieldResolver.d.ts +0 -20
  14. package/lib/dslgen/printers/fieldResolver/enumFieldResolver.d.ts.map +0 -1
  15. package/lib/dslgen/printers/fieldResolver/enumFieldResolver.js +0 -61
  16. package/lib/dslgen/printers/fieldResolver/nonNullResolver.d.ts +0 -3
  17. package/lib/dslgen/printers/fieldResolver/nonNullResolver.d.ts.map +0 -1
  18. package/lib/dslgen/printers/fieldResolver/nonNullResolver.js +0 -10
  19. package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts +0 -14
  20. package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts.map +0 -1
  21. package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.js +0 -45
  22. package/lib/dslgen/printers/index.d.ts +0 -5
  23. package/lib/dslgen/printers/index.d.ts.map +0 -1
  24. package/lib/dslgen/printers/index.js +0 -28
  25. package/lib/dslgen/printers/inputObjectType.d.ts +0 -19
  26. package/lib/dslgen/printers/inputObjectType.d.ts.map +0 -1
  27. package/lib/dslgen/printers/inputObjectType.js +0 -59
  28. package/lib/dslgen/printers/objectType.d.ts +0 -15
  29. package/lib/dslgen/printers/objectType.d.ts.map +0 -1
  30. package/lib/dslgen/printers/objectType.js +0 -50
  31. package/lib/dslgen/printers/oneofUnionType.d.ts +0 -14
  32. package/lib/dslgen/printers/oneofUnionType.d.ts.map +0 -1
  33. package/lib/dslgen/printers/oneofUnionType.js +0 -27
  34. package/lib/dslgen/printers/util.d.ts +0 -12
  35. package/lib/dslgen/printers/util.d.ts.map +0 -1
  36. package/lib/dslgen/printers/util.js +0 -69
  37. package/lib/printer.d.ts +0 -11
  38. package/lib/printer.d.ts.map +0 -1
  39. package/lib/printer.js +0 -34
  40. package/lib/process.d.ts +0 -2
  41. package/lib/process.d.ts.map +0 -1
  42. package/lib/process.js +0 -6
  43. package/lib/protoc-gen-pothos.d.ts +0 -2
  44. package/lib/protoc-gen-pothos.d.ts.map +0 -1
  45. package/lib/protoc-gen-pothos.js +0 -5
  46. package/module/dslgen/index.d.ts +0 -2
  47. package/module/dslgen/index.d.ts.map +0 -1
  48. package/module/dslgen/index.js +0 -1
  49. package/module/dslgen/printers/enumType.d.ts +0 -16
  50. package/module/dslgen/printers/enumType.d.ts.map +0 -1
  51. package/module/dslgen/printers/enumType.js +0 -36
  52. package/module/dslgen/printers/field.d.ts +0 -41
  53. package/module/dslgen/printers/field.d.ts.map +0 -1
  54. package/module/dslgen/printers/field.js +0 -94
  55. package/module/dslgen/printers/fieldResolver/enumFieldResolver.d.ts +0 -20
  56. package/module/dslgen/printers/fieldResolver/enumFieldResolver.d.ts.map +0 -1
  57. package/module/dslgen/printers/fieldResolver/enumFieldResolver.js +0 -57
  58. package/module/dslgen/printers/fieldResolver/nonNullResolver.d.ts +0 -3
  59. package/module/dslgen/printers/fieldResolver/nonNullResolver.d.ts.map +0 -1
  60. package/module/dslgen/printers/fieldResolver/nonNullResolver.js +0 -6
  61. package/module/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts +0 -14
  62. package/module/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts.map +0 -1
  63. package/module/dslgen/printers/fieldResolver/oneofUnionResolver.js +0 -41
  64. package/module/dslgen/printers/index.d.ts +0 -5
  65. package/module/dslgen/printers/index.d.ts.map +0 -1
  66. package/module/dslgen/printers/index.js +0 -24
  67. package/module/dslgen/printers/inputObjectType.d.ts +0 -19
  68. package/module/dslgen/printers/inputObjectType.d.ts.map +0 -1
  69. package/module/dslgen/printers/inputObjectType.js +0 -55
  70. package/module/dslgen/printers/objectType.d.ts +0 -15
  71. package/module/dslgen/printers/objectType.d.ts.map +0 -1
  72. package/module/dslgen/printers/objectType.js +0 -46
  73. package/module/dslgen/printers/oneofUnionType.d.ts +0 -14
  74. package/module/dslgen/printers/oneofUnionType.d.ts.map +0 -1
  75. package/module/dslgen/printers/oneofUnionType.js +0 -23
  76. package/module/dslgen/printers/util.d.ts +0 -12
  77. package/module/dslgen/printers/util.d.ts.map +0 -1
  78. package/module/dslgen/printers/util.js +0 -37
  79. package/module/printer.d.ts +0 -11
  80. package/module/printer.d.ts.map +0 -1
  81. package/module/printer.js +0 -30
  82. package/module/process.d.ts +0 -2
  83. package/module/process.d.ts.map +0 -1
  84. package/module/process.js +0 -3
  85. package/module/protoc-gen-pothos.d.ts +0 -2
  86. package/module/protoc-gen-pothos.d.ts.map +0 -1
  87. package/module/protoc-gen-pothos.js +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Masayuki Izumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,4 +2,53 @@
2
2
 
3
3
  Build GraphQL schema from Protobuf and [Pothos GraphQL](https://pothos-graphql.dev/).
4
4
 
5
- - repository: https://github.com/proto-graphql/proto-graphql-js
5
+ ## Supported Protocol Buffers Implementations
6
+
7
+ - [ts-proto](https://github.com/stephenh/ts-proto)
8
+
9
+ ## Configuration with [Buf](https://docs.buf.build/installation)
10
+
11
+ ```yaml
12
+ # proto/buf.yaml
13
+ version: v1
14
+ deps:
15
+ - buf.build/proto-graphql/proto-graphql
16
+ ```
17
+
18
+ ### with [ts-proto](https://github.com/stephenh/ts-proto)
19
+
20
+ ```yaml
21
+ # proto/buf.gen.yaml
22
+ version: v1
23
+ plugins:
24
+ - name: ts
25
+ out: ../src/__generated__/proto
26
+ strategy: all
27
+ path: ../node_modules/.bin/protoc-gen-ts_proto
28
+ opt:
29
+ - esModuleInterop=true # required
30
+ - unrecognizedEnum=false # required
31
+ - outputTypeRegistry=true # required
32
+ strategy: all
33
+ - name: pothos
34
+ path: ../node_modules/.bin/protoc-gen-pothos
35
+ out: ../src/__generated__/pothos
36
+ opt:
37
+ - pothos_builder_path=../../builder
38
+ - import_prefix=../proto
39
+ ```
40
+
41
+ ### Supported options
42
+
43
+ - `import_prefix` (`string`, required)
44
+ - path to out dir of ts-proto
45
+ - `pothos_builder_path` (`string`, required)
46
+ - path to file that exports pothos builder
47
+ - `emit_imported_files` (`bool`, optional)
48
+ - if `true`, protoc-gen-pothos also emits types defined in imported `.proto` file.
49
+ - `custom_type` (`string`, optional)
50
+ - `long_number` (`string`, optional, default `String`)
51
+
52
+ ## Author
53
+
54
+ - Masayuki Izumi ([twitter: @izumin5210](https://github.com/izumin5210), [github: @izumin5210](https://github.com/izumin5210))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protoc-gen-pothos",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Generate DSL for Pothos GraphQL from Protocol Buffers IDL",
5
5
  "keywords": [
6
6
  "graphql",
@@ -23,24 +23,30 @@
23
23
  "node": ">= 14.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@proto-graphql/codegen-core": "^0.3.2",
27
- "@proto-graphql/proto-descriptors": "^0.3.1",
28
- "@proto-graphql/protoc-plugin-helpers": "^0.2.3",
29
26
  "google-protobuf": "^3.21.2",
30
- "ts-poet": "^6.3.0"
27
+ "ts-poet": "^6.3.0",
28
+ "@proto-graphql/codegen-core": "0.3.3",
29
+ "@proto-graphql/proto-descriptors": "0.3.2",
30
+ "@proto-graphql/protoc-plugin-helpers": "0.2.5"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/google-protobuf": "^3.15.6"
33
+ "@proto-graphql/eslint-config": "0.1.0",
34
+ "@proto-graphql/testapis-proto": "0.1.0",
35
+ "@proto-graphql/tsconfig": "0.1.0"
34
36
  },
35
37
  "files": [
36
38
  "bin/",
37
- "include/",
38
39
  "lib/",
39
40
  "module/"
40
41
  ],
41
42
  "scripts": {
42
- "build": "tsc --build tsconfig.cjs.json && tsc --build tsconfig.module.json",
43
- "clean": "rimraf lib/ module/ && tsc --build tsconfig.cjs.json --clean && tsc --build tsconfig.module.json --clean",
43
+ "build": "pnpm run build:cjs && pnpm run build:module",
44
+ "build:cjs": "tsc --build tsconfig.cjs.json",
45
+ "build:module": "tsc --build tsconfig.module.json",
46
+ "clean": "pnpm run clean:cjs && pnpm run clean:module",
47
+ "clean:cjs": "pnpm run build:cjs --clean",
48
+ "clean:module": "pnpm run build:module --clean",
49
+ "lint": "eslint --fix .",
44
50
  "test": "jest --coverage"
45
51
  }
46
- }
52
+ }
@@ -1,2 +0,0 @@
1
- export * from "./printers";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dslgen/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./printers"), exports);
@@ -1,16 +0,0 @@
1
- import { EnumType } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- import { PothosPrinterOptions } from "./util";
4
- /**
5
- * @example
6
- * ```ts
7
- * export cosnt Hello$Ref = builder.enumType("Hello", {
8
- * values: [
9
- * // ...
10
- * ],
11
- * // ...
12
- * })
13
- * ```
14
- */
15
- export declare function createEnumTypeCode(type: EnumType, opts: PothosPrinterOptions): Code;
16
- //# sourceMappingURL=enumType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enumType.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/enumType.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAET,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAQ,IAAI,EAAuB,MAAM,SAAS,CAAC;AAE1D,OAAO,EAAiB,oBAAoB,EAAa,MAAM,QAAQ,CAAC;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,oBAAoB,GACzB,IAAI,CA8BN"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEnumTypeCode = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const ts_poet_1 = require("ts-poet");
6
- const util_1 = require("./util");
7
- /**
8
- * @example
9
- * ```ts
10
- * export cosnt Hello$Ref = builder.enumType("Hello", {
11
- * values: [
12
- * // ...
13
- * ],
14
- * // ...
15
- * })
16
- * ```
17
- */
18
- function createEnumTypeCode(type, opts) {
19
- const typeOpts = {
20
- description: type.description,
21
- values: (0, ts_poet_1.code) `{${(0, ts_poet_1.joinCode)(type.values
22
- .filter((v) => !v.isIgnored() && !v.isUnespecified())
23
- .map((ev) => (0, ts_poet_1.code) `${ev.name}: ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)({
24
- description: ev.description,
25
- deprecationReason: ev.deprecationReason,
26
- value: ev.number,
27
- extensions: {
28
- protobufEnumValue: {
29
- name: ev.proto.name,
30
- },
31
- },
32
- }))},`))}} as const`,
33
- extensions: (0, codegen_core_1.protobufGraphQLExtensions)(type),
34
- };
35
- return (0, ts_poet_1.code) `
36
- export const ${(0, util_1.pothosRef)(type)} =
37
- ${(0, util_1.pothosBuilder)(type, opts)}.enumType(${(0, ts_poet_1.literalOf)(type.typeName)}, ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)(typeOpts))});
38
- `;
39
- }
40
- exports.createEnumTypeCode = createEnumTypeCode;
@@ -1,41 +0,0 @@
1
- import { InputObjectField, ObjectField, ObjectOneofField } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- import { PothosPrinterOptions } from "./util";
4
- /**
5
- * @example
6
- * ```ts
7
- * t.expose("name", {
8
- * type: "Boolean",
9
- * nullable: true,
10
- * description: "...",
11
- * })
12
- * ```
13
- * ```ts
14
- * t.field({
15
- * type: "Boolean",
16
- * nullable: true,
17
- * description: "...",
18
- * resolve() {
19
- * return true
20
- * }
21
- * })
22
- * ```
23
- */
24
- export declare function createFieldRefCode(field: ObjectField<any> | ObjectOneofField | InputObjectField<any>, opts: PothosPrinterOptions): Code;
25
- /**
26
- * @example
27
- * ```ts
28
- * t.field( {
29
- * type: "Boolean",
30
- * nullable: true,
31
- * description: "noop field",
32
- * resolve() {
33
- * return true
34
- * }
35
- * })
36
- * ```
37
- */
38
- export declare function createNoopFieldRefCode(opts: {
39
- input: boolean;
40
- }): Code;
41
- //# sourceMappingURL=field.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAKjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAQ,IAAI,EAAa,MAAM,SAAS,CAAC;AAKhD,OAAO,EAAgB,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAClE,IAAI,EAAE,oBAAoB,GACzB,IAAI,CAoDN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CASrE"}
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNoopFieldRefCode = exports.createFieldRefCode = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const ts_poet_1 = require("ts-poet");
6
- const enumFieldResolver_1 = require("./fieldResolver/enumFieldResolver");
7
- const nonNullResolver_1 = require("./fieldResolver/nonNullResolver");
8
- const oneofUnionResolver_1 = require("./fieldResolver/oneofUnionResolver");
9
- const util_1 = require("./util");
10
- /**
11
- * @example
12
- * ```ts
13
- * t.expose("name", {
14
- * type: "Boolean",
15
- * nullable: true,
16
- * description: "...",
17
- * })
18
- * ```
19
- * ```ts
20
- * t.field({
21
- * type: "Boolean",
22
- * nullable: true,
23
- * description: "...",
24
- * resolve() {
25
- * return true
26
- * }
27
- * })
28
- * ```
29
- */
30
- function createFieldRefCode(field, opts) {
31
- const isInput = field instanceof codegen_core_1.InputObjectField;
32
- const baseType = field.type instanceof codegen_core_1.ScalarType
33
- ? (0, ts_poet_1.literalOf)(field.type.typeName)
34
- : (0, util_1.fieldTypeRef)(field, opts);
35
- const sourceExpr = (0, ts_poet_1.code) `source`;
36
- let resolverCode;
37
- if (!isInput) {
38
- if (field instanceof codegen_core_1.ObjectOneofField) {
39
- resolverCode = (0, oneofUnionResolver_1.createOneofUnionResolverCode)(sourceExpr, field);
40
- }
41
- else {
42
- const valueExpr = (0, codegen_core_1.createGetFieldValueCode)(sourceExpr, field.proto, opts);
43
- const nullableInProto = field.type instanceof codegen_core_1.ObjectType ||
44
- (field.type instanceof codegen_core_1.ScalarType &&
45
- !field.type.isPrimitive() &&
46
- !field.type.isWrapperType());
47
- if (nullableInProto && !field.isNullable()) {
48
- resolverCode = (0, nonNullResolver_1.createNonNullResolverCode)(valueExpr);
49
- }
50
- if (field.type instanceof codegen_core_1.EnumType && field instanceof codegen_core_1.ObjectField) {
51
- resolverCode = (0, enumFieldResolver_1.createEnumResolverCode)(valueExpr, field, opts);
52
- }
53
- if (field.type instanceof codegen_core_1.SquashedOneofUnionType &&
54
- field instanceof codegen_core_1.ObjectField) {
55
- resolverCode = (0, oneofUnionResolver_1.createOneofUnionResolverCode)(valueExpr, field);
56
- }
57
- }
58
- }
59
- const nullableValue = isInput !== field.isNullable(); /* Logical XOR */
60
- const fieldOpts = {
61
- type: field.isList() ? (0, ts_poet_1.code) `[${baseType}]` : baseType,
62
- [isInput ? "required" : "nullable"]: field.isList()
63
- ? { list: nullableValue, items: isInput /* always non-null */ }
64
- : nullableValue,
65
- description: field.description,
66
- deprecationReason: field.deprecationReason,
67
- resolve: resolverCode ? (0, ts_poet_1.code) `${sourceExpr} => {${resolverCode}}` : null,
68
- extensions: (0, codegen_core_1.protobufGraphQLExtensions)(field),
69
- };
70
- const shouldUseFieldFunc = isInput || resolverCode != null;
71
- return shouldUseFieldFunc
72
- ? (0, ts_poet_1.code) `t.field(${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)(fieldOpts))})`
73
- : (0, ts_poet_1.code) `t.expose(${(0, ts_poet_1.literalOf)(field.proto.jsonName)}, ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)(fieldOpts))})`;
74
- }
75
- exports.createFieldRefCode = createFieldRefCode;
76
- /**
77
- * @example
78
- * ```ts
79
- * t.field( {
80
- * type: "Boolean",
81
- * nullable: true,
82
- * description: "noop field",
83
- * resolve() {
84
- * return true
85
- * }
86
- * })
87
- * ```
88
- */
89
- function createNoopFieldRefCode(opts) {
90
- return (0, ts_poet_1.code) `
91
- t.field({
92
- type: "Boolean",
93
- ${opts.input ? "required: false" : "nullable: true"},
94
- description: "noop field",
95
- ${opts.input ? "" : "resolve: () => true,"}
96
- })
97
- `;
98
- }
99
- exports.createNoopFieldRefCode = createNoopFieldRefCode;
@@ -1,20 +0,0 @@
1
- import { EnumType, ObjectField, PrinterOptions } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- /**
4
- * @example nullable
5
- * ```ts
6
- * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {
7
- * return null
8
- * }
9
- * return root.myEnum
10
- * ```
11
- * @example notNull
12
- * ```ts
13
- * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {
14
- * throw new Error("Message.field is required field. but got null or unspecified.")
15
- * }
16
- * return root.myEnum
17
- * ```
18
- */
19
- export declare function createEnumResolverCode(valueExpr: Code, field: ObjectField<EnumType>, opts: PrinterOptions): Code;
20
- //# sourceMappingURL=enumFieldResolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enumFieldResolver.d.ts","sourceRoot":"","sources":["../../../../src/dslgen/printers/fieldResolver/enumFieldResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,cAAc,EAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,IAAI,EAAQ,MAAM,SAAS,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,EAC5B,IAAI,EAAE,cAAc,GACnB,IAAI,CA8CN"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEnumResolverCode = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const ts_poet_1 = require("ts-poet");
6
- /**
7
- * @example nullable
8
- * ```ts
9
- * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {
10
- * return null
11
- * }
12
- * return root.myEnum
13
- * ```
14
- * @example notNull
15
- * ```ts
16
- * if (!root.myEnum || root.myEnum === _$enums.myEnum.MY_ENUM_UNSPECIFIED) {
17
- * throw new Error("Message.field is required field. but got null or unspecified.")
18
- * }
19
- * return root.myEnum
20
- * ```
21
- */
22
- function createEnumResolverCode(valueExpr, field, opts) {
23
- const createBlockStmtCodes = (valueExpr) => {
24
- const chunks = [];
25
- if (field.type.unspecifiedValue != null) {
26
- const escapeCode = field.isNullable() && !field.isList()
27
- ? (0, ts_poet_1.code) `return null;`
28
- : (0, ts_poet_1.code) `throw new Error("${field.name} is required field. But got unspecified.");`;
29
- chunks.push((0, ts_poet_1.code) `
30
- if (${valueExpr} === ${(0, codegen_core_1.protoType)(field.type.proto, opts)}.${field.type.unspecifiedValue.proto.name}) {
31
- ${escapeCode}
32
- }
33
- `);
34
- }
35
- for (const ev of field.type.valuesWithIgnored) {
36
- if (!ev.isIgnored())
37
- continue;
38
- chunks.push((0, ts_poet_1.code) `
39
- if (${valueExpr} === ${(0, codegen_core_1.protoType)(field.type.proto, opts)}.${ev.proto.name}) {
40
- throw new Error("${ev.name} is ignored in GraphQL schema");
41
- }
42
- `);
43
- }
44
- return chunks;
45
- };
46
- if (field.isList()) {
47
- const stmts = createBlockStmtCodes((0, ts_poet_1.code) `item`);
48
- if (stmts.length === 0) {
49
- return (0, ts_poet_1.code) `return ${valueExpr}`;
50
- }
51
- return (0, ts_poet_1.code) `return ${valueExpr}.map(item => {
52
- ${stmts}
53
- return item;
54
- })`;
55
- }
56
- return (0, ts_poet_1.code) `
57
- ${createBlockStmtCodes(valueExpr)}
58
- return ${valueExpr};
59
- `;
60
- }
61
- exports.createEnumResolverCode = createEnumResolverCode;
@@ -1,3 +0,0 @@
1
- import { Code } from "ts-poet";
2
- export declare function createNonNullResolverCode(valueExpr: Code): Code;
3
- //# sourceMappingURL=nonNullResolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nonNullResolver.d.ts","sourceRoot":"","sources":["../../../../src/dslgen/printers/fieldResolver/nonNullResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,IAAI,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAI/D"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNonNullResolverCode = void 0;
4
- const ts_poet_1 = require("ts-poet");
5
- function createNonNullResolverCode(valueExpr) {
6
- return (0, ts_poet_1.code) `
7
- return ${valueExpr}!;
8
- `;
9
- }
10
- exports.createNonNullResolverCode = createNonNullResolverCode;
@@ -1,14 +0,0 @@
1
- import { ObjectField, ObjectOneofField, SquashedOneofUnionType } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- /**
4
- * @example nullable
5
- * ```ts
6
- * const value = source.v1 ?? source.v2 ?? source.v3;
7
- * if (value != null) {
8
- * throw new Error("...");
9
- * }
10
- * return value
11
- * ```
12
- */
13
- export declare function createOneofUnionResolverCode(sourceExpr: Code, field: ObjectOneofField | ObjectField<SquashedOneofUnionType>): Code;
14
- //# sourceMappingURL=oneofUnionResolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oneofUnionResolver.d.ts","sourceRoot":"","sources":["../../../../src/dslgen/printers/fieldResolver/oneofUnionResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,IAAI,EAChB,KAAK,EAAE,gBAAgB,GAAG,WAAW,CAAC,sBAAsB,CAAC,GAC5D,IAAI,CAoCN"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOneofUnionResolverCode = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const ts_poet_1 = require("ts-poet");
6
- /**
7
- * @example nullable
8
- * ```ts
9
- * const value = source.v1 ?? source.v2 ?? source.v3;
10
- * if (value != null) {
11
- * throw new Error("...");
12
- * }
13
- * return value
14
- * ```
15
- */
16
- function createOneofUnionResolverCode(sourceExpr, field) {
17
- const createBlockStmtCode = (sourceExpr, { nullable }) => {
18
- const createFieldExpr = (memberField) => {
19
- if (field instanceof codegen_core_1.ObjectOneofField) {
20
- return (0, ts_poet_1.code) `${sourceExpr}.${memberField.proto.jsonName}`;
21
- }
22
- return (0, ts_poet_1.code) `${sourceExpr}?.${memberField.proto.jsonName}`;
23
- };
24
- return (0, ts_poet_1.code) `
25
- const value = ${(0, ts_poet_1.joinCode)(field.type.fields.map(createFieldExpr), {
26
- on: "??",
27
- })};
28
- if (value == null) {
29
- ${nullable
30
- ? "return null"
31
- : `throw new Error("${field.name} should not be null")`};
32
- }
33
- return value;
34
- `;
35
- };
36
- if (field instanceof codegen_core_1.ObjectField && field.isList()) {
37
- return (0, ts_poet_1.code) `
38
- return ${sourceExpr}.map(item => {
39
- ${createBlockStmtCode((0, ts_poet_1.code) `item`, { nullable: false })}
40
- })
41
- `;
42
- }
43
- return createBlockStmtCode(sourceExpr, { nullable: field.isNullable() });
44
- }
45
- exports.createOneofUnionResolverCode = createOneofUnionResolverCode;
@@ -1,5 +0,0 @@
1
- import { EnumType, InputObjectType, ObjectType, OneofUnionType, SquashedOneofUnionType } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- import { PothosPrinterOptions } from "./util";
4
- export declare function createTypeDslCodes(types: (ObjectType | InputObjectType | EnumType | OneofUnionType | SquashedOneofUnionType)[], opts: PothosPrinterOptions): Code[];
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,eAAe,EACf,UAAU,EACV,cAAc,EACd,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAM/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE9C,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,CACH,UAAU,GACV,eAAe,GACf,QAAQ,GACR,cAAc,GACd,sBAAsB,CACzB,EAAE,EACH,IAAI,EAAE,oBAAoB,GACzB,IAAI,EAAE,CAqBR"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTypeDslCodes = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const enumType_1 = require("./enumType");
6
- const inputObjectType_1 = require("./inputObjectType");
7
- const objectType_1 = require("./objectType");
8
- const oneofUnionType_1 = require("./oneofUnionType");
9
- function createTypeDslCodes(types, opts) {
10
- return types.flatMap((type) => {
11
- if (type instanceof codegen_core_1.ObjectType) {
12
- return (0, objectType_1.createObjectTypeCode)(type, opts);
13
- }
14
- if (type instanceof codegen_core_1.InputObjectType) {
15
- return (0, inputObjectType_1.createInputObjectTypeCode)(type, opts);
16
- }
17
- if (type instanceof codegen_core_1.EnumType) {
18
- return [(0, enumType_1.createEnumTypeCode)(type, opts)];
19
- }
20
- if (type instanceof codegen_core_1.OneofUnionType ||
21
- type instanceof codegen_core_1.SquashedOneofUnionType) {
22
- return [(0, oneofUnionType_1.createOneofUnionTypeCode)(type, opts)];
23
- }
24
- const _exhaustiveCheck = type;
25
- throw "unreachable";
26
- });
27
- }
28
- exports.createTypeDslCodes = createTypeDslCodes;
@@ -1,19 +0,0 @@
1
- import { InputObjectType } from "@proto-graphql/codegen-core";
2
- import { Code } from "ts-poet";
3
- import { PothosPrinterOptions } from "./util";
4
- /**
5
- * @example
6
- * ```ts
7
- * export type HelloInput$Shape = {
8
- * // ...
9
- * }
10
- * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef("HelloInput").implement({
11
- * description: "...",
12
- * fields: (t) => ({
13
- * // ...
14
- * }),
15
- * })
16
- * ```
17
- */
18
- export declare function createInputObjectTypeCode(type: InputObjectType, opts: PothosPrinterOptions): Code;
19
- //# sourceMappingURL=inputObjectType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inputObjectType.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/inputObjectType.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAGhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,IAAI,EAAkC,MAAM,SAAS,CAAC;AAG/D,OAAO,EAGL,oBAAoB,EAGrB,MAAM,QAAQ,CAAC;AAEhB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,eAAe,EACrB,IAAI,EAAE,oBAAoB,GACzB,IAAI,CAkDN"}
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createInputObjectTypeCode = void 0;
4
- const codegen_core_1 = require("@proto-graphql/codegen-core");
5
- const ts_poet_1 = require("ts-poet");
6
- const field_1 = require("./field");
7
- const util_1 = require("./util");
8
- /**
9
- * @example
10
- * ```ts
11
- * export type HelloInput$Shape = {
12
- * // ...
13
- * }
14
- * export const HelloInput$Ref: pothos.InputObjectRef<Hello$SHape> = builder.inputRef("HelloInput").implement({
15
- * description: "...",
16
- * fields: (t) => ({
17
- * // ...
18
- * }),
19
- * })
20
- * ```
21
- */
22
- function createInputObjectTypeCode(type, opts) {
23
- const shapeTypeCode = (0, ts_poet_1.code) `
24
- export type ${(0, util_1.shapeType)(type)} = {
25
- ${(0, ts_poet_1.joinCode)(type.fields.map((f) => {
26
- let typeNode;
27
- if (f.type instanceof codegen_core_1.InputObjectType) {
28
- // @ts-expect-error f should be inferred as InputObjectField<InputObjectType>
29
- typeNode = (0, ts_poet_1.code) `${(0, util_1.fieldTypeShape)(f, opts)}`;
30
- if (f.isList())
31
- typeNode = (0, ts_poet_1.code) `Array<${typeNode}>`;
32
- }
33
- else {
34
- typeNode = (0, ts_poet_1.code) `${(0, codegen_core_1.protoType)(type.proto, opts)}[${(0, ts_poet_1.literalOf)(f.proto.jsonName)}]`;
35
- }
36
- return f.isNullable()
37
- ? (0, ts_poet_1.code) `${f.name}?: ${typeNode} | null,`
38
- : (0, ts_poet_1.code) `${f.name}: ${typeNode},`;
39
- }))}
40
- };
41
- `;
42
- const refCode = (0, ts_poet_1.code) `
43
- export const ${(0, util_1.pothosRef)(type)}: ${(0, ts_poet_1.imp)("InputObjectRef@@pothos/core")}<${(0, util_1.shapeType)(type)}> =
44
- ${(0, util_1.pothosBuilder)(type, opts)}.inputRef<${(0, util_1.shapeType)(type)}>(${(0, ts_poet_1.literalOf)(type.typeName)}).implement(
45
- ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)({
46
- description: type.description,
47
- fields: (0, ts_poet_1.code) `t => ({${type.fields.length > 0
48
- ? type.fields.map((f) => (0, ts_poet_1.code) `${f.name}: ${(0, field_1.createFieldRefCode)(f, opts)},`)
49
- : (0, ts_poet_1.code) `_: ${(0, field_1.createNoopFieldRefCode)({ input: true })}`}})`,
50
- extensions: (0, codegen_core_1.protobufGraphQLExtensions)(type),
51
- }))}
52
- );
53
- `;
54
- return (0, ts_poet_1.code) `
55
- ${shapeTypeCode}
56
- ${refCode}
57
- `;
58
- }
59
- exports.createInputObjectTypeCode = createInputObjectTypeCode;