protoc-gen-pothos 0.1.2 → 0.2.1

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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # protoc-gen-pothos
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
9
+ - [#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
10
+
11
+ - [#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
12
+
13
+ - Updated dependencies [[`c7db053`](https://github.com/proto-graphql/proto-graphql-js/commit/c7db0531f3790dbf61d740440eda841459cb3f6b)]:
14
+ - @proto-graphql/codegen-core@0.2.1
15
+
16
+ ## 0.2.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#224](https://github.com/proto-graphql/proto-graphql-js/pull/224) [`6c25f40`](https://github.com/proto-graphql/proto-graphql-js/commit/6c25f4035f1b788a63bf005dbc52ca5d0bd5f2a2) Thanks [@izumin5210](https://github.com/izumin5210)! - support `long_number` param for mapping 64bit numbers to GraphQL Int
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [[`6c25f40`](https://github.com/proto-graphql/proto-graphql-js/commit/6c25f4035f1b788a63bf005dbc52ca5d0bd5f2a2)]:
25
+ - @proto-graphql/codegen-core@0.2.0
26
+ - @proto-graphql/protoc-plugin-helpers@0.2.0
27
+
3
28
  ## 0.1.2
4
29
 
5
30
  ### Patch 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,18 @@ 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
+ return typescript_1.default.factory.createObjectLiteralExpression([
127
+ typescript_1.default.factory.createPropertyAssignment("protobufField", typescript_1.default.factory.createObjectLiteralExpression([typescript_1.default.factory.createPropertyAssignment("name", typescript_1.default.factory.createStringLiteral(field.proto.name))], true)),
128
+ ], true);
129
+ }
@@ -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
- // ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
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
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
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,18 @@ 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
+ return ts.factory.createObjectLiteralExpression([
119
+ ts.factory.createPropertyAssignment("protobufField", ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.proto.name))], true)),
120
+ ], true);
121
+ }
@@ -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
- // ts.factory.createPropertyAssignment("extensions", createExtensionsObjectLiteralExpr(type)),
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
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
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.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "Generate DSL for Pothos GraphQL from Protocol Buffers IDL",
5
5
  "keywords": [
6
6
  "graphql",
@@ -23,14 +23,16 @@
23
23
  "node": ">= 14.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@proto-graphql/codegen-core": "^0.1.2",
26
+ "@proto-graphql/codegen-core": "^0.2.1",
27
27
  "@proto-graphql/proto-descriptors": "^0.1.0",
28
- "@proto-graphql/protoc-plugin-helpers": "^0.1.1",
28
+ "@proto-graphql/protoc-plugin-helpers": "^0.2.0",
29
29
  "google-protobuf": "^3.20.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@pothos/core": "^3.22.7",
33
33
  "@testapis/ts-proto": "^0.5.1",
34
+ "@testapis/ts-proto-with-forcelong-long": "^0.6.0",
35
+ "@testapis/ts-proto-with-forcelong-number": "^0.6.0",
34
36
  "@types/glob": "^8.0.0",
35
37
  "glob": "^8.0.1"
36
38
  },
@@ -43,7 +45,6 @@
43
45
  "scripts": {
44
46
  "build": "tsc --build . && tsc --build tsconfig.module.json",
45
47
  "clean": "rimraf lib/ module/ && tsc --build . --clean && tsc --build tsconfig.module.json --clean",
46
- "test": "jest --coverage",
47
- "test:integration": "TEST_TARGET=integration jest"
48
+ "test": "jest --coverage"
48
49
  }
49
50
  }