protoc-gen-pothos 0.3.3 → 0.3.4
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/lib/dslgen/index.d.ts +2 -0
- package/lib/dslgen/index.d.ts.map +1 -0
- package/lib/dslgen/index.js +17 -0
- package/lib/dslgen/printers/enumType.d.ts +16 -0
- package/lib/dslgen/printers/enumType.d.ts.map +1 -0
- package/lib/dslgen/printers/enumType.js +40 -0
- package/lib/dslgen/printers/field.d.ts +41 -0
- package/lib/dslgen/printers/field.d.ts.map +1 -0
- package/lib/dslgen/printers/field.js +99 -0
- package/lib/dslgen/printers/fieldResolver/enumFieldResolver.d.ts +20 -0
- package/lib/dslgen/printers/fieldResolver/enumFieldResolver.d.ts.map +1 -0
- package/lib/dslgen/printers/fieldResolver/enumFieldResolver.js +61 -0
- package/lib/dslgen/printers/fieldResolver/nonNullResolver.d.ts +3 -0
- package/lib/dslgen/printers/fieldResolver/nonNullResolver.d.ts.map +1 -0
- package/lib/dslgen/printers/fieldResolver/nonNullResolver.js +10 -0
- package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts +14 -0
- package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts.map +1 -0
- package/lib/dslgen/printers/fieldResolver/oneofUnionResolver.js +45 -0
- package/lib/dslgen/printers/index.d.ts +5 -0
- package/lib/dslgen/printers/index.d.ts.map +1 -0
- package/lib/dslgen/printers/index.js +28 -0
- package/lib/dslgen/printers/inputObjectType.d.ts +19 -0
- package/lib/dslgen/printers/inputObjectType.d.ts.map +1 -0
- package/lib/dslgen/printers/inputObjectType.js +61 -0
- package/lib/dslgen/printers/objectType.d.ts +15 -0
- package/lib/dslgen/printers/objectType.d.ts.map +1 -0
- package/lib/dslgen/printers/objectType.js +50 -0
- package/lib/dslgen/printers/oneofUnionType.d.ts +14 -0
- package/lib/dslgen/printers/oneofUnionType.d.ts.map +1 -0
- package/lib/dslgen/printers/oneofUnionType.js +27 -0
- package/lib/dslgen/printers/util.d.ts +12 -0
- package/lib/dslgen/printers/util.d.ts.map +1 -0
- package/lib/dslgen/printers/util.js +69 -0
- package/lib/printer.d.ts +11 -0
- package/lib/printer.d.ts.map +1 -0
- package/lib/printer.js +34 -0
- package/lib/process.d.ts +2 -0
- package/lib/process.d.ts.map +1 -0
- package/lib/process.js +6 -0
- package/lib/protoc-gen-pothos.d.ts +2 -0
- package/lib/protoc-gen-pothos.d.ts.map +1 -0
- package/lib/protoc-gen-pothos.js +5 -0
- package/module/dslgen/index.d.ts +2 -0
- package/module/dslgen/index.d.ts.map +1 -0
- package/module/dslgen/index.js +1 -0
- package/module/dslgen/printers/enumType.d.ts +16 -0
- package/module/dslgen/printers/enumType.d.ts.map +1 -0
- package/module/dslgen/printers/enumType.js +36 -0
- package/module/dslgen/printers/field.d.ts +41 -0
- package/module/dslgen/printers/field.d.ts.map +1 -0
- package/module/dslgen/printers/field.js +94 -0
- package/module/dslgen/printers/fieldResolver/enumFieldResolver.d.ts +20 -0
- package/module/dslgen/printers/fieldResolver/enumFieldResolver.d.ts.map +1 -0
- package/module/dslgen/printers/fieldResolver/enumFieldResolver.js +57 -0
- package/module/dslgen/printers/fieldResolver/nonNullResolver.d.ts +3 -0
- package/module/dslgen/printers/fieldResolver/nonNullResolver.d.ts.map +1 -0
- package/module/dslgen/printers/fieldResolver/nonNullResolver.js +6 -0
- package/module/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts +14 -0
- package/module/dslgen/printers/fieldResolver/oneofUnionResolver.d.ts.map +1 -0
- package/module/dslgen/printers/fieldResolver/oneofUnionResolver.js +41 -0
- package/module/dslgen/printers/index.d.ts +5 -0
- package/module/dslgen/printers/index.d.ts.map +1 -0
- package/module/dslgen/printers/index.js +24 -0
- package/module/dslgen/printers/inputObjectType.d.ts +19 -0
- package/module/dslgen/printers/inputObjectType.d.ts.map +1 -0
- package/module/dslgen/printers/inputObjectType.js +57 -0
- package/module/dslgen/printers/objectType.d.ts +15 -0
- package/module/dslgen/printers/objectType.d.ts.map +1 -0
- package/module/dslgen/printers/objectType.js +46 -0
- package/module/dslgen/printers/oneofUnionType.d.ts +14 -0
- package/module/dslgen/printers/oneofUnionType.d.ts.map +1 -0
- package/module/dslgen/printers/oneofUnionType.js +23 -0
- package/module/dslgen/printers/util.d.ts +12 -0
- package/module/dslgen/printers/util.d.ts.map +1 -0
- package/module/dslgen/printers/util.js +37 -0
- package/module/printer.d.ts +11 -0
- package/module/printer.d.ts.map +1 -0
- package/module/printer.js +30 -0
- package/module/process.d.ts +2 -0
- package/module/process.d.ts.map +1 -0
- package/module/process.js +3 -0
- package/module/protoc-gen-pothos.d.ts +2 -0
- package/module/protoc-gen-pothos.d.ts.map +1 -0
- package/module/protoc-gen-pothos.js +3 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dslgen/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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);
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputObjectType.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/inputObjectType.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAIhB,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,CAsDN"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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}: ${f.type instanceof codegen_core_1.ScalarType && f.type.isCustomScalar()
|
|
39
|
+
? (0, ts_poet_1.code) `NonNullable<${typeNode}>`
|
|
40
|
+
: typeNode},`;
|
|
41
|
+
}))}
|
|
42
|
+
};
|
|
43
|
+
`;
|
|
44
|
+
const refCode = (0, ts_poet_1.code) `
|
|
45
|
+
export const ${(0, util_1.pothosRef)(type)}: ${(0, ts_poet_1.imp)("InputObjectRef@@pothos/core")}<${(0, util_1.shapeType)(type)}> =
|
|
46
|
+
${(0, util_1.pothosBuilder)(type, opts)}.inputRef<${(0, util_1.shapeType)(type)}>(${(0, ts_poet_1.literalOf)(type.typeName)}).implement(
|
|
47
|
+
${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)({
|
|
48
|
+
description: type.description,
|
|
49
|
+
fields: (0, ts_poet_1.code) `t => ({${type.fields.length > 0
|
|
50
|
+
? type.fields.map((f) => (0, ts_poet_1.code) `${f.name}: ${(0, field_1.createFieldRefCode)(f, opts)},`)
|
|
51
|
+
: (0, ts_poet_1.code) `_: ${(0, field_1.createNoopFieldRefCode)({ input: true })}`}})`,
|
|
52
|
+
extensions: (0, codegen_core_1.protobufGraphQLExtensions)(type),
|
|
53
|
+
}))}
|
|
54
|
+
);
|
|
55
|
+
`;
|
|
56
|
+
return (0, ts_poet_1.code) `
|
|
57
|
+
${shapeTypeCode}
|
|
58
|
+
${refCode}
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
exports.createInputObjectTypeCode = createInputObjectTypeCode;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ObjectType } from "@proto-graphql/codegen-core";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import { PothosPrinterOptions } from "./util";
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* export const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>("Hello")
|
|
8
|
+
* builder.objectType(Hello$Ref, {
|
|
9
|
+
* name: "Hello",
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function createObjectTypeCode(type: ObjectType, opts: PothosPrinterOptions): Code;
|
|
15
|
+
//# sourceMappingURL=objectType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectType.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/objectType.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAGX,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAC;AAG1D,OAAO,EAAiB,oBAAoB,EAAa,MAAM,QAAQ,CAAC;AAExE;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,oBAAoB,GACzB,IAAI,CAoDN"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createObjectTypeCode = 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 const Hello$Ref = builder.objectRef<_$hello$hello_pb.Hello>("Hello")
|
|
12
|
+
* builder.objectType(Hello$Ref, {
|
|
13
|
+
* name: "Hello",
|
|
14
|
+
* // ...
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function createObjectTypeCode(type, opts) {
|
|
19
|
+
const isInterface = type instanceof codegen_core_1.InterfaceType;
|
|
20
|
+
const typeOpts = {
|
|
21
|
+
name: type.typeName,
|
|
22
|
+
fields: (0, ts_poet_1.code) `t => ({${type.fields.length > 0
|
|
23
|
+
? (0, ts_poet_1.joinCode)(type.fields.map((f) => (0, ts_poet_1.code) `${f.name}: ${(0, field_1.createFieldRefCode)(f, opts)},`))
|
|
24
|
+
: (0, ts_poet_1.code) `_: ${(0, field_1.createNoopFieldRefCode)({ input: false })}`}})`,
|
|
25
|
+
description: type.description,
|
|
26
|
+
isTypeOf: isInterface
|
|
27
|
+
? undefined
|
|
28
|
+
: (0, ts_poet_1.code) `
|
|
29
|
+
(source) => {
|
|
30
|
+
return (source as ${(0, codegen_core_1.protoType)(type.proto, opts)} | { $type: string & {} }).$type
|
|
31
|
+
=== ${(0, ts_poet_1.literalOf)(type.proto.fullName.toString())};
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
extensions: (0, codegen_core_1.protobufGraphQLExtensions)(type),
|
|
35
|
+
};
|
|
36
|
+
const buildRefFunc = (0, ts_poet_1.code) `${(0, util_1.pothosBuilder)(type, opts)}.${isInterface ? "interface" : "object"}Ref`;
|
|
37
|
+
const buildTypeFunc = (0, ts_poet_1.code) `${(0, util_1.pothosBuilder)(type, opts)}.${isInterface ? "interface" : "object"}Type`;
|
|
38
|
+
const refFuncTypeArg = isInterface
|
|
39
|
+
? (0, ts_poet_1.code) `
|
|
40
|
+
Pick<
|
|
41
|
+
${(0, codegen_core_1.protoType)(type.proto, opts)},
|
|
42
|
+
${(0, ts_poet_1.joinCode)(type.fields.map((f) => (0, ts_poet_1.code) `${(0, ts_poet_1.literalOf)(f.proto.jsonName)}`), { on: "|" })}
|
|
43
|
+
>`
|
|
44
|
+
: (0, codegen_core_1.protoType)(type.proto, opts);
|
|
45
|
+
return (0, ts_poet_1.code) `
|
|
46
|
+
export const ${(0, util_1.pothosRef)(type)} = ${buildRefFunc}<${refFuncTypeArg}>(${(0, ts_poet_1.literalOf)(type.typeName)});
|
|
47
|
+
${buildTypeFunc}(${(0, util_1.pothosRef)(type)}, ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)(typeOpts))});
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
exports.createObjectTypeCode = createObjectTypeCode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OneofUnionType, SquashedOneofUnionType } from "@proto-graphql/codegen-core";
|
|
2
|
+
import { Code } from "ts-poet";
|
|
3
|
+
import { PothosPrinterOptions } from "./util";
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* export cosnt Oneof = builder.unionType("Oneof", {
|
|
8
|
+
* types: [...],
|
|
9
|
+
* // ...
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function createOneofUnionTypeCode(type: OneofUnionType | SquashedOneofUnionType, opts: PothosPrinterOptions): Code;
|
|
14
|
+
//# sourceMappingURL=oneofUnionType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oneofUnionType.d.ts","sourceRoot":"","sources":["../../../src/dslgen/printers/oneofUnionType.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAQ,IAAI,EAAa,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAiB,oBAAoB,EAAa,MAAM,QAAQ,CAAC;AAExE;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,cAAc,GAAG,sBAAsB,EAC7C,IAAI,EAAE,oBAAoB,GACzB,IAAI,CAYN"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOneofUnionTypeCode = 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 Oneof = builder.unionType("Oneof", {
|
|
11
|
+
* types: [...],
|
|
12
|
+
* // ...
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function createOneofUnionTypeCode(type, opts) {
|
|
17
|
+
const typeOpts = {
|
|
18
|
+
types: type.fields.map((f) => (0, util_1.pothosRef)(f.type)),
|
|
19
|
+
description: type.description,
|
|
20
|
+
extensions: (0, codegen_core_1.protobufGraphQLExtensions)(type),
|
|
21
|
+
};
|
|
22
|
+
return (0, ts_poet_1.code) `
|
|
23
|
+
export const ${(0, util_1.pothosRef)(type)} =
|
|
24
|
+
${(0, util_1.pothosBuilder)(type, opts)}.unionType(${(0, ts_poet_1.literalOf)(type.typeName)}, ${(0, ts_poet_1.literalOf)((0, codegen_core_1.compact)(typeOpts))});
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
exports.createOneofUnionTypeCode = createOneofUnionTypeCode;
|