protoc-gen-pothos 0.2.0 → 0.2.2
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/CHANGELOG.md +26 -0
- package/lib/dslgen/printers/enumType.js +38 -0
- package/lib/dslgen/printers/field.js +30 -0
- package/lib/dslgen/printers/inputObjectType.js +22 -1
- package/lib/dslgen/printers/objectType.js +22 -0
- package/lib/dslgen/printers/oneofUnionType.js +49 -0
- package/module/dslgen/printers/enumType.js +38 -0
- package/module/dslgen/printers/field.js +30 -0
- package/module/dslgen/printers/inputObjectType.js +22 -1
- package/module/dslgen/printers/objectType.js +22 -0
- package/module/dslgen/printers/oneofUnionType.js +49 -0
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# protoc-gen-pothos
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#234](https://github.com/proto-graphql/proto-graphql-js/pull/234) [`a2a3e60`](https://github.com/proto-graphql/proto-graphql-js/commit/a2a3e60789f75c31c600333afd830a02ac0cccf8) Thanks [@izumin5210](https://github.com/izumin5210)! - support `ProtoScalar` in `ProtoField.type`
|
|
8
|
+
|
|
9
|
+
- [#236](https://github.com/proto-graphql/proto-graphql-js/pull/236) [`3410d43`](https://github.com/proto-graphql/proto-graphql-js/commit/3410d43a7d29d04e1ed52576ac8a28e9b43cb452) Thanks [@izumin5210](https://github.com/izumin5210)! - add `typeFullName` to extensions in GraphQLField
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`a2a3e60`](https://github.com/proto-graphql/proto-graphql-js/commit/a2a3e60789f75c31c600333afd830a02ac0cccf8)]:
|
|
12
|
+
- @proto-graphql/codegen-core@0.2.2
|
|
13
|
+
- @proto-graphql/proto-descriptors@0.2.0
|
|
14
|
+
- @proto-graphql/protoc-plugin-helpers@0.2.1
|
|
15
|
+
|
|
16
|
+
## 0.2.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#231](https://github.com/proto-graphql/proto-graphql-js/pull/231) [`2ff07a6`](https://github.com/proto-graphql/proto-graphql-js/commit/2ff07a64212a62010330803d05c2f8f7f37f29b4) Thanks [@izumin5210](https://github.com/izumin5210)! - add oroginal protobuf type info to extensions
|
|
21
|
+
|
|
22
|
+
- [#228](https://github.com/proto-graphql/proto-graphql-js/pull/228) [`c7db053`](https://github.com/proto-graphql/proto-graphql-js/commit/c7db0531f3790dbf61d740440eda841459cb3f6b) Thanks [@izumin5210](https://github.com/izumin5210)! - Support PothosShemaBuilder in external modules
|
|
23
|
+
|
|
24
|
+
- [#216](https://github.com/proto-graphql/proto-graphql-js/pull/216) [`831f8e7`](https://github.com/proto-graphql/proto-graphql-js/commit/831f8e70ff45d3503413441f568c2c901ae6f552) Thanks [@izumin5210](https://github.com/izumin5210)! - new E2E testing
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`c7db053`](https://github.com/proto-graphql/proto-graphql-js/commit/c7db0531f3790dbf61d740440eda841459cb3f6b)]:
|
|
27
|
+
- @proto-graphql/codegen-core@0.2.1
|
|
28
|
+
|
|
3
29
|
## 0.2.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
|
@@ -23,6 +23,7 @@ function createEnumTypeDslStmt(type) {
|
|
|
23
23
|
.filter((v) => !v.isIgnored() && !v.isUnespecified())
|
|
24
24
|
.map((ev) => typescript_1.default.factory.createPropertyAssignment(ev.name, createEnumValueExpr(ev))), true // multiline
|
|
25
25
|
), typescript_1.default.factory.createTypeReferenceNode("const"))),
|
|
26
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
26
27
|
].filter((0, util_1.onlyNonNull)()), true),
|
|
27
28
|
]));
|
|
28
29
|
}
|
|
@@ -32,6 +33,43 @@ function createEnumValueExpr(ev) {
|
|
|
32
33
|
(0, util_1.createDescriptionPropertyAssignment)(ev),
|
|
33
34
|
(0, util_1.createDeprecationPropertyAssignment)(ev),
|
|
34
35
|
typescript_1.default.factory.createPropertyAssignment("value", typescript_1.default.factory.createNumericLiteral(ev.number)),
|
|
36
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExprForEnumValue(ev)),
|
|
35
37
|
].filter((0, util_1.onlyNonNull)()), true // multiline
|
|
36
38
|
);
|
|
37
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* {{
|
|
44
|
+
* protobufEnum: {
|
|
45
|
+
* name: "...",
|
|
46
|
+
* fullName: "...",
|
|
47
|
+
* package: "...",
|
|
48
|
+
* },
|
|
49
|
+
* } as ProtobufEnumExtensions)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
53
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
54
|
+
typescript_1.default.factory.createPropertyAssignment("protobufEnum", typescript_1.default.factory.createObjectLiteralExpression([
|
|
55
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(type.proto.name)),
|
|
56
|
+
typescript_1.default.factory.createPropertyAssignment("fullName", typescript_1.default.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
57
|
+
typescript_1.default.factory.createPropertyAssignment("package", typescript_1.default.factory.createStringLiteral(type.proto.file.package)),
|
|
58
|
+
], true)),
|
|
59
|
+
], true);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* ({
|
|
65
|
+
* protobufEnumValue: {
|
|
66
|
+
* name: "...",
|
|
67
|
+
* },
|
|
68
|
+
* } as ProtobufEnumValueExtensions)
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function createExtensionsObjectLiteralExprForEnumValue(ev) {
|
|
72
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
73
|
+
typescript_1.default.factory.createPropertyAssignment("protobufEnumValue", typescript_1.default.factory.createObjectLiteralExpression([typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(ev.proto.name))], true)),
|
|
74
|
+
], true);
|
|
75
|
+
}
|
|
@@ -73,6 +73,7 @@ function createFieldDefinitionExpr(field) {
|
|
|
73
73
|
(0, util_1.createDeprecationPropertyAssignment)(field),
|
|
74
74
|
// defaultValueExpr && ts.factory.createPropertyAssignment("defaultValue", defaultValueExpr),
|
|
75
75
|
createResolveStmts && typescript_1.default.factory.createPropertyAssignment("resolve", createResolverExpr(createResolveStmts)),
|
|
76
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(field)),
|
|
76
77
|
].filter((0, util_1.onlyNonNull)()), true);
|
|
77
78
|
const shouldUseFieldFunc = field instanceof codegen_core_1.InputObjectField || createResolveStmts != null;
|
|
78
79
|
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier("t"), typescript_1.default.factory.createIdentifier(shouldUseFieldFunc ? "field" : "expose")), undefined, shouldUseFieldFunc ? [fieldOptionsExpr] : [typescript_1.default.factory.createStringLiteral(field.protoJsName), fieldOptionsExpr]);
|
|
@@ -111,3 +112,32 @@ exports.createNoopFieldDefinitionExpr = createNoopFieldDefinitionExpr;
|
|
|
111
112
|
function createResolverExpr(createStmts) {
|
|
112
113
|
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [typescript_1.default.factory.createParameterDeclaration(undefined, undefined, undefined, typescript_1.default.factory.createIdentifier("source"))], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createBlock(createStmts(typescript_1.default.factory.createIdentifier("source")), true));
|
|
113
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* ({
|
|
119
|
+
* protobufField: {
|
|
120
|
+
* name: "...",
|
|
121
|
+
* },
|
|
122
|
+
* } as ProtobufFieldExtensions)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
function createExtensionsObjectLiteralExpr(field) {
|
|
126
|
+
let typeName;
|
|
127
|
+
if ((field instanceof codegen_core_1.ObjectField || field instanceof codegen_core_1.InputObjectField) && field.proto.type !== null) {
|
|
128
|
+
if (field.proto.type.kind === "Scalar") {
|
|
129
|
+
typeName = field.proto.type.type;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
typeName = field.proto.type.fullName.toString();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
136
|
+
typescript_1.default.factory.createPropertyAssignment("protobufField", typescript_1.default.factory.createObjectLiteralExpression([
|
|
137
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(field.proto.name)),
|
|
138
|
+
typeName
|
|
139
|
+
? typescript_1.default.factory.createPropertyAssignment("typeFullName", typescript_1.default.factory.createStringLiteral(typeName))
|
|
140
|
+
: undefined,
|
|
141
|
+
].filter((0, util_1.onlyNonNull)()), true)),
|
|
142
|
+
], true);
|
|
143
|
+
}
|
|
@@ -28,7 +28,7 @@ function createInputObjectTypeDslStmts(type) {
|
|
|
28
28
|
typescript_1.default.factory.createObjectLiteralExpression([
|
|
29
29
|
(0, util_1.createDescriptionPropertyAssignment)(type),
|
|
30
30
|
typescript_1.default.factory.createPropertyAssignment("fields", createInputObjectTypeFieldsMethodExpr(type)),
|
|
31
|
-
|
|
31
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
32
32
|
].filter((0, util_1.onlyNonNull)()), true),
|
|
33
33
|
])),
|
|
34
34
|
];
|
|
@@ -77,3 +77,24 @@ function createInputObjectTypeShapeDecl(type) {
|
|
|
77
77
|
function createInputObjectTypeShapeIdent(type) {
|
|
78
78
|
return typescript_1.default.factory.createIdentifier(`${type.typeName}$Shape`);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* {
|
|
84
|
+
* protobufMessage: {
|
|
85
|
+
* fullName: "...",
|
|
86
|
+
* name: "...",
|
|
87
|
+
* package: "...",
|
|
88
|
+
* },
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
93
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
94
|
+
typescript_1.default.factory.createPropertyAssignment("protobufMessage", typescript_1.default.factory.createObjectLiteralExpression([
|
|
95
|
+
typescript_1.default.factory.createPropertyAssignment("fullName", typescript_1.default.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
96
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(type.proto.name)),
|
|
97
|
+
typescript_1.default.factory.createPropertyAssignment("package", typescript_1.default.factory.createStringLiteral(type.proto.file.package)),
|
|
98
|
+
], true)),
|
|
99
|
+
], true);
|
|
100
|
+
}
|
|
@@ -36,6 +36,7 @@ function createObjectTypeDslStmts(objType) {
|
|
|
36
36
|
(0, util_1.createDescriptionPropertyAssignment)(objType),
|
|
37
37
|
typescript_1.default.factory.createPropertyAssignment("fields", createObjectTypeFieldsFuncExpr(objType)),
|
|
38
38
|
isInterface ? null : typescript_1.default.factory.createPropertyAssignment("isTypeOf", createIsTypeOfMethodExpr(objType)),
|
|
39
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(objType)),
|
|
39
40
|
].filter((0, util_1.onlyNonNull)()), true),
|
|
40
41
|
])),
|
|
41
42
|
];
|
|
@@ -79,3 +80,24 @@ function createIsTypeOfMethodExpr(objType) {
|
|
|
79
80
|
]))), "$type"), typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken, typescript_1.default.factory.createStringLiteral(objType.proto.fullName.toString()))),
|
|
80
81
|
], true));
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* {
|
|
87
|
+
* protobufMessage: {
|
|
88
|
+
* fullName: "...",
|
|
89
|
+
* name: "...",
|
|
90
|
+
* package: "...",
|
|
91
|
+
* },
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
function createExtensionsObjectLiteralExpr(objType) {
|
|
96
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
97
|
+
typescript_1.default.factory.createPropertyAssignment("protobufMessage", typescript_1.default.factory.createObjectLiteralExpression([
|
|
98
|
+
typescript_1.default.factory.createPropertyAssignment("fullName", typescript_1.default.factory.createStringLiteral(objType.proto.fullName.toString())),
|
|
99
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(objType.proto.name)),
|
|
100
|
+
typescript_1.default.factory.createPropertyAssignment("package", typescript_1.default.factory.createStringLiteral(objType.proto.file.package)),
|
|
101
|
+
], true)),
|
|
102
|
+
], true);
|
|
103
|
+
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createOneofUnionTypeDslStmt = void 0;
|
|
7
|
+
const codegen_core_1 = require("@proto-graphql/codegen-core");
|
|
7
8
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
9
|
const util_1 = require("./util");
|
|
9
10
|
/**
|
|
@@ -21,7 +22,55 @@ function createOneofUnionTypeDslStmt(type) {
|
|
|
21
22
|
typescript_1.default.factory.createObjectLiteralExpression([
|
|
22
23
|
(0, util_1.createDescriptionPropertyAssignment)(type),
|
|
23
24
|
typescript_1.default.factory.createPropertyAssignment("types", typescript_1.default.factory.createArrayLiteralExpression(type.fields.map((f) => typescript_1.default.factory.createIdentifier(f.type.pothosRefObjectName)), true)),
|
|
25
|
+
typescript_1.default.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
24
26
|
].filter((0, util_1.onlyNonNull)()), true),
|
|
25
27
|
]));
|
|
26
28
|
}
|
|
27
29
|
exports.createOneofUnionTypeDslStmt = createOneofUnionTypeDslStmt;
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* {
|
|
34
|
+
* protobufMessage: {
|
|
35
|
+
* fullName: "...",
|
|
36
|
+
* name: "...",
|
|
37
|
+
* package: "...",
|
|
38
|
+
* },
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
43
|
+
if (type instanceof codegen_core_1.SquashedOneofUnionType) {
|
|
44
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
45
|
+
typescript_1.default.factory.createPropertyAssignment("protobufMessage", typescript_1.default.factory.createObjectLiteralExpression([
|
|
46
|
+
typescript_1.default.factory.createPropertyAssignment("fullName", typescript_1.default.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
47
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(type.proto.name)),
|
|
48
|
+
typescript_1.default.factory.createPropertyAssignment("package", typescript_1.default.factory.createStringLiteral(type.proto.file.package)),
|
|
49
|
+
typescript_1.default.factory.createPropertyAssignment("fields", typescript_1.default.factory.createArrayLiteralExpression(type.proto.oneofs[0].fields.map((f) => typescript_1.default.factory.createObjectLiteralExpression([
|
|
50
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(f.name)),
|
|
51
|
+
...(f.type && f.type.kind !== "Scalar"
|
|
52
|
+
? [
|
|
53
|
+
typescript_1.default.factory.createPropertyAssignment("type", typescript_1.default.factory.createStringLiteral(f.type.fullName.toString())),
|
|
54
|
+
]
|
|
55
|
+
: []),
|
|
56
|
+
], true)), true)),
|
|
57
|
+
], true)),
|
|
58
|
+
], true);
|
|
59
|
+
}
|
|
60
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
61
|
+
typescript_1.default.factory.createPropertyAssignment("protobufOneof", typescript_1.default.factory.createObjectLiteralExpression([
|
|
62
|
+
typescript_1.default.factory.createPropertyAssignment("fullName", typescript_1.default.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
63
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(type.proto.name)),
|
|
64
|
+
typescript_1.default.factory.createPropertyAssignment("messageName", typescript_1.default.factory.createStringLiteral(type.proto.parent.name)),
|
|
65
|
+
typescript_1.default.factory.createPropertyAssignment("package", typescript_1.default.factory.createStringLiteral(type.proto.parent.file.package)),
|
|
66
|
+
typescript_1.default.factory.createPropertyAssignment("fields", typescript_1.default.factory.createArrayLiteralExpression(type.proto.fields.map((f) => typescript_1.default.factory.createObjectLiteralExpression([
|
|
67
|
+
typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(f.name)),
|
|
68
|
+
...(f.type && f.type.kind !== "Scalar"
|
|
69
|
+
? [
|
|
70
|
+
typescript_1.default.factory.createPropertyAssignment("type", typescript_1.default.factory.createStringLiteral(f.type.fullName.toString())),
|
|
71
|
+
]
|
|
72
|
+
: []),
|
|
73
|
+
], true)), true)),
|
|
74
|
+
], true)),
|
|
75
|
+
], true);
|
|
76
|
+
}
|
|
@@ -17,6 +17,7 @@ export function createEnumTypeDslStmt(type) {
|
|
|
17
17
|
.filter((v) => !v.isIgnored() && !v.isUnespecified())
|
|
18
18
|
.map((ev) => ts.factory.createPropertyAssignment(ev.name, createEnumValueExpr(ev))), true // multiline
|
|
19
19
|
), ts.factory.createTypeReferenceNode("const"))),
|
|
20
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
20
21
|
].filter(onlyNonNull()), true),
|
|
21
22
|
]));
|
|
22
23
|
}
|
|
@@ -25,6 +26,43 @@ function createEnumValueExpr(ev) {
|
|
|
25
26
|
createDescriptionPropertyAssignment(ev),
|
|
26
27
|
createDeprecationPropertyAssignment(ev),
|
|
27
28
|
ts.factory.createPropertyAssignment("value", ts.factory.createNumericLiteral(ev.number)),
|
|
29
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExprForEnumValue(ev)),
|
|
28
30
|
].filter(onlyNonNull()), true // multiline
|
|
29
31
|
);
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* {{
|
|
37
|
+
* protobufEnum: {
|
|
38
|
+
* name: "...",
|
|
39
|
+
* fullName: "...",
|
|
40
|
+
* package: "...",
|
|
41
|
+
* },
|
|
42
|
+
* } as ProtobufEnumExtensions)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
46
|
+
return ts.factory.createObjectLiteralExpression([
|
|
47
|
+
ts.factory.createPropertyAssignment("protobufEnum", ts.factory.createObjectLiteralExpression([
|
|
48
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(type.proto.name)),
|
|
49
|
+
ts.factory.createPropertyAssignment("fullName", ts.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
50
|
+
ts.factory.createPropertyAssignment("package", ts.factory.createStringLiteral(type.proto.file.package)),
|
|
51
|
+
], true)),
|
|
52
|
+
], true);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* ({
|
|
58
|
+
* protobufEnumValue: {
|
|
59
|
+
* name: "...",
|
|
60
|
+
* },
|
|
61
|
+
* } as ProtobufEnumValueExtensions)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function createExtensionsObjectLiteralExprForEnumValue(ev) {
|
|
65
|
+
return ts.factory.createObjectLiteralExpression([
|
|
66
|
+
ts.factory.createPropertyAssignment("protobufEnumValue", ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(ev.proto.name))], true)),
|
|
67
|
+
], true);
|
|
68
|
+
}
|
|
@@ -67,6 +67,7 @@ export function createFieldDefinitionExpr(field) {
|
|
|
67
67
|
createDeprecationPropertyAssignment(field),
|
|
68
68
|
// defaultValueExpr && ts.factory.createPropertyAssignment("defaultValue", defaultValueExpr),
|
|
69
69
|
createResolveStmts && ts.factory.createPropertyAssignment("resolve", createResolverExpr(createResolveStmts)),
|
|
70
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(field)),
|
|
70
71
|
].filter(onlyNonNull()), true);
|
|
71
72
|
const shouldUseFieldFunc = field instanceof InputObjectField || createResolveStmts != null;
|
|
72
73
|
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("t"), ts.factory.createIdentifier(shouldUseFieldFunc ? "field" : "expose")), undefined, shouldUseFieldFunc ? [fieldOptionsExpr] : [ts.factory.createStringLiteral(field.protoJsName), fieldOptionsExpr]);
|
|
@@ -103,3 +104,32 @@ export function createNoopFieldDefinitionExpr(opts) {
|
|
|
103
104
|
function createResolverExpr(createStmts) {
|
|
104
105
|
return ts.factory.createArrowFunction(undefined, undefined, [ts.factory.createParameterDeclaration(undefined, undefined, undefined, ts.factory.createIdentifier("source"))], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createBlock(createStmts(ts.factory.createIdentifier("source")), true));
|
|
105
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* ({
|
|
111
|
+
* protobufField: {
|
|
112
|
+
* name: "...",
|
|
113
|
+
* },
|
|
114
|
+
* } as ProtobufFieldExtensions)
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
function createExtensionsObjectLiteralExpr(field) {
|
|
118
|
+
let typeName;
|
|
119
|
+
if ((field instanceof ObjectField || field instanceof InputObjectField) && field.proto.type !== null) {
|
|
120
|
+
if (field.proto.type.kind === "Scalar") {
|
|
121
|
+
typeName = field.proto.type.type;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
typeName = field.proto.type.fullName.toString();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return ts.factory.createObjectLiteralExpression([
|
|
128
|
+
ts.factory.createPropertyAssignment("protobufField", ts.factory.createObjectLiteralExpression([
|
|
129
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.proto.name)),
|
|
130
|
+
typeName
|
|
131
|
+
? ts.factory.createPropertyAssignment("typeFullName", ts.factory.createStringLiteral(typeName))
|
|
132
|
+
: undefined,
|
|
133
|
+
].filter(onlyNonNull()), true)),
|
|
134
|
+
], true);
|
|
135
|
+
}
|
|
@@ -22,7 +22,7 @@ export function createInputObjectTypeDslStmts(type) {
|
|
|
22
22
|
ts.factory.createObjectLiteralExpression([
|
|
23
23
|
createDescriptionPropertyAssignment(type),
|
|
24
24
|
ts.factory.createPropertyAssignment("fields", createInputObjectTypeFieldsMethodExpr(type)),
|
|
25
|
-
|
|
25
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
26
26
|
].filter(onlyNonNull()), true),
|
|
27
27
|
])),
|
|
28
28
|
];
|
|
@@ -70,3 +70,24 @@ function createInputObjectTypeShapeDecl(type) {
|
|
|
70
70
|
function createInputObjectTypeShapeIdent(type) {
|
|
71
71
|
return ts.factory.createIdentifier(`${type.typeName}$Shape`);
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* {
|
|
77
|
+
* protobufMessage: {
|
|
78
|
+
* fullName: "...",
|
|
79
|
+
* name: "...",
|
|
80
|
+
* package: "...",
|
|
81
|
+
* },
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
86
|
+
return ts.factory.createObjectLiteralExpression([
|
|
87
|
+
ts.factory.createPropertyAssignment("protobufMessage", ts.factory.createObjectLiteralExpression([
|
|
88
|
+
ts.factory.createPropertyAssignment("fullName", ts.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
89
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(type.proto.name)),
|
|
90
|
+
ts.factory.createPropertyAssignment("package", ts.factory.createStringLiteral(type.proto.file.package)),
|
|
91
|
+
], true)),
|
|
92
|
+
], true);
|
|
93
|
+
}
|
|
@@ -30,6 +30,7 @@ export function createObjectTypeDslStmts(objType) {
|
|
|
30
30
|
createDescriptionPropertyAssignment(objType),
|
|
31
31
|
ts.factory.createPropertyAssignment("fields", createObjectTypeFieldsFuncExpr(objType)),
|
|
32
32
|
isInterface ? null : ts.factory.createPropertyAssignment("isTypeOf", createIsTypeOfMethodExpr(objType)),
|
|
33
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(objType)),
|
|
33
34
|
].filter(onlyNonNull()), true),
|
|
34
35
|
])),
|
|
35
36
|
];
|
|
@@ -72,3 +73,24 @@ function createIsTypeOfMethodExpr(objType) {
|
|
|
72
73
|
]))), "$type"), ts.SyntaxKind.EqualsEqualsEqualsToken, ts.factory.createStringLiteral(objType.proto.fullName.toString()))),
|
|
73
74
|
], true));
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* {
|
|
80
|
+
* protobufMessage: {
|
|
81
|
+
* fullName: "...",
|
|
82
|
+
* name: "...",
|
|
83
|
+
* package: "...",
|
|
84
|
+
* },
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
function createExtensionsObjectLiteralExpr(objType) {
|
|
89
|
+
return ts.factory.createObjectLiteralExpression([
|
|
90
|
+
ts.factory.createPropertyAssignment("protobufMessage", ts.factory.createObjectLiteralExpression([
|
|
91
|
+
ts.factory.createPropertyAssignment("fullName", ts.factory.createStringLiteral(objType.proto.fullName.toString())),
|
|
92
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(objType.proto.name)),
|
|
93
|
+
ts.factory.createPropertyAssignment("package", ts.factory.createStringLiteral(objType.proto.file.package)),
|
|
94
|
+
], true)),
|
|
95
|
+
], true);
|
|
96
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SquashedOneofUnionType } from "@proto-graphql/codegen-core";
|
|
1
2
|
import ts from "typescript";
|
|
2
3
|
import { createBuilderCallExpr, createDescriptionPropertyAssignment, createDslExportConstStmt, onlyNonNull, } from "./util";
|
|
3
4
|
/**
|
|
@@ -15,6 +16,54 @@ export function createOneofUnionTypeDslStmt(type) {
|
|
|
15
16
|
ts.factory.createObjectLiteralExpression([
|
|
16
17
|
createDescriptionPropertyAssignment(type),
|
|
17
18
|
ts.factory.createPropertyAssignment("types", ts.factory.createArrayLiteralExpression(type.fields.map((f) => ts.factory.createIdentifier(f.type.pothosRefObjectName)), true)),
|
|
19
|
+
ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
|
|
18
20
|
].filter(onlyNonNull()), true),
|
|
19
21
|
]));
|
|
20
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* {
|
|
27
|
+
* protobufMessage: {
|
|
28
|
+
* fullName: "...",
|
|
29
|
+
* name: "...",
|
|
30
|
+
* package: "...",
|
|
31
|
+
* },
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function createExtensionsObjectLiteralExpr(type) {
|
|
36
|
+
if (type instanceof SquashedOneofUnionType) {
|
|
37
|
+
return ts.factory.createObjectLiteralExpression([
|
|
38
|
+
ts.factory.createPropertyAssignment("protobufMessage", ts.factory.createObjectLiteralExpression([
|
|
39
|
+
ts.factory.createPropertyAssignment("fullName", ts.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
40
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(type.proto.name)),
|
|
41
|
+
ts.factory.createPropertyAssignment("package", ts.factory.createStringLiteral(type.proto.file.package)),
|
|
42
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createArrayLiteralExpression(type.proto.oneofs[0].fields.map((f) => ts.factory.createObjectLiteralExpression([
|
|
43
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(f.name)),
|
|
44
|
+
...(f.type && f.type.kind !== "Scalar"
|
|
45
|
+
? [
|
|
46
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(f.type.fullName.toString())),
|
|
47
|
+
]
|
|
48
|
+
: []),
|
|
49
|
+
], true)), true)),
|
|
50
|
+
], true)),
|
|
51
|
+
], true);
|
|
52
|
+
}
|
|
53
|
+
return ts.factory.createObjectLiteralExpression([
|
|
54
|
+
ts.factory.createPropertyAssignment("protobufOneof", ts.factory.createObjectLiteralExpression([
|
|
55
|
+
ts.factory.createPropertyAssignment("fullName", ts.factory.createStringLiteral(type.proto.fullName.toString())),
|
|
56
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(type.proto.name)),
|
|
57
|
+
ts.factory.createPropertyAssignment("messageName", ts.factory.createStringLiteral(type.proto.parent.name)),
|
|
58
|
+
ts.factory.createPropertyAssignment("package", ts.factory.createStringLiteral(type.proto.parent.file.package)),
|
|
59
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createArrayLiteralExpression(type.proto.fields.map((f) => ts.factory.createObjectLiteralExpression([
|
|
60
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(f.name)),
|
|
61
|
+
...(f.type && f.type.kind !== "Scalar"
|
|
62
|
+
? [
|
|
63
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(f.type.fullName.toString())),
|
|
64
|
+
]
|
|
65
|
+
: []),
|
|
66
|
+
], true)), true)),
|
|
67
|
+
], true)),
|
|
68
|
+
], true);
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protoc-gen-pothos",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Generate DSL for Pothos GraphQL from Protocol Buffers IDL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"node": ">= 14.0.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@proto-graphql/codegen-core": "^0.2.
|
|
27
|
-
"@proto-graphql/proto-descriptors": "^0.
|
|
28
|
-
"@proto-graphql/protoc-plugin-helpers": "^0.2.
|
|
26
|
+
"@proto-graphql/codegen-core": "^0.2.2",
|
|
27
|
+
"@proto-graphql/proto-descriptors": "^0.2.0",
|
|
28
|
+
"@proto-graphql/protoc-plugin-helpers": "^0.2.1",
|
|
29
29
|
"google-protobuf": "^3.20.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsc --build . && tsc --build tsconfig.module.json",
|
|
47
47
|
"clean": "rimraf lib/ module/ && tsc --build . --clean && tsc --build tsconfig.module.json --clean",
|
|
48
|
-
"test": "jest --coverage"
|
|
49
|
-
"test:integration": "TEST_TARGET=integration jest"
|
|
48
|
+
"test": "jest --coverage"
|
|
50
49
|
}
|
|
51
50
|
}
|