Skip to content

Commit

Permalink
Merge pull request #68 from izumin5210/izumin5210/protogen
Browse files Browse the repository at this point in the history
extract protogen package
  • Loading branch information
izumin5210 authored Jan 4, 2021
2 parents 4676b35 + 64f2e24 commit f788121
Show file tree
Hide file tree
Showing 29 changed files with 1,017 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ type Query {
\\"\\"\\"\\"\\"\\"
enum TestPrefixPrefixedEnum {
\\"\\"\\"\\"\\"\\"
PREFIXED_BAR
\\"\\"\\"\\"\\"\\"
PREFIXED_FOO
}
Expand Down Expand Up @@ -109,7 +112,10 @@ type Query {
\\"\\"\\"\\"\\"\\"
enum TestPrefixPrefixedEnum {
\\"\\"\\"\\"\\"\\"
PREFIXED_BAR
\\"\\"\\"\\"\\"\\"
PREFIXED_FOO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ exports[`schema generation with protobufjs can make GraphQL schema from generate
\\"\\"\\"\\"\\"\\"
enum DeprecatedEnum {
\\"\\"\\"\\"\\"\\"
DEPRECATED_BAZ @deprecated(reason: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\")
\\"\\"\\"\\"\\"\\"
DEPRECATED_QUX @deprecated(reason: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\")
}
\\"\\"\\"\\"\\"\\"
enum DeprecatedFileEnum {
\\"\\"\\"\\"\\"\\"
DEPRECATED_FILE_BAR @deprecated(reason: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\")
\\"\\"\\"\\"\\"\\"
DEPRECATED_FILE_FOO @deprecated(reason: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\")
}
Expand Down Expand Up @@ -79,7 +85,10 @@ input DeprecatedMessageInput {
\\"\\"\\"\\"\\"\\"
enum NotDeprecatedEnum {
\\"\\"\\"\\"\\"\\"
DEPRECATED_BAR @deprecated(reason: \\"testapis.deprecation.NotDeprecatedEnum.DEPRECATED_BAR is mark as deprecated in a *.proto file.\\")
\\"\\"\\"\\"\\"\\"
NOT_DEPRECATED_FOO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ input MessageWithEnumsInput {
enum MyEnum {
\\"\\"\\"This is Bar.\\"\\"\\"
MY_ENUM_BAR
\\"\\"\\"\\"\\"\\"
MY_ENUM_BAZ
\\"\\"\\"\\"\\"\\"
MY_ENUM_FOO
}
\\"\\"\\"\\"\\"\\"
enum MyEnumWithoutUnspecified {
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_BAR
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_BAZ
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_FOO
}
Expand Down Expand Up @@ -95,14 +104,23 @@ input MessageWithEnumsInput {
enum MyEnum {
\\"\\"\\"This is Bar.\\"\\"\\"
MY_ENUM_BAR
\\"\\"\\"\\"\\"\\"
MY_ENUM_BAZ
\\"\\"\\"\\"\\"\\"
MY_ENUM_FOO
}
\\"\\"\\"\\"\\"\\"
enum MyEnumWithoutUnspecified {
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_BAR
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_BAZ
\\"\\"\\"\\"\\"\\"
MY_ENUM_WITHOUT_UNSPECIFIED_FOO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ type Query {
\\"\\"\\"\\"\\"\\"
enum SubpkgEnum {
\\"\\"\\"\\"\\"\\"
BAR
\\"\\"\\"\\"\\"\\"
FOO
}
Expand Down Expand Up @@ -76,7 +79,10 @@ type Query {
\\"\\"\\"\\"\\"\\"
enum SubpkgEnum {
\\"\\"\\"\\"\\"\\"
BAR
\\"\\"\\"\\"\\"\\"
FOO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ input ParentMessageInput {
\\"\\"\\"\\"\\"\\"
enum ParentMessageNestedEnum {
\\"\\"\\"\\"\\"\\"
BAR
\\"\\"\\"\\"\\"\\"
FOO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ export const NotDeprecatedEnum = enumType({
members: [
{
name: \\"NOT_DEPRECATED_FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"DEPRECATED_BAR\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.NotDeprecatedEnum.DEPRECATED_BAR is mark as deprecated in a *.proto file.\\",
value: 2
}
Expand All @@ -295,11 +297,13 @@ export const DeprecatedEnum = enumType({
members: [
{
name: \\"DEPRECATED_BAZ\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\",
value: 1
},
{
name: \\"DEPRECATED_QUX\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\",
value: 2
}
Expand Down Expand Up @@ -396,11 +400,13 @@ export const DeprecatedFileEnum = enumType({
members: [
{
name: \\"DEPRECATED_FILE_FOO\\",
description: \\"\\",
deprecation: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\",
value: 1
},
{
name: \\"DEPRECATED_FILE_BAR\\",
description: \\"\\",
deprecation: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\",
value: 2
}
Expand Down Expand Up @@ -702,10 +708,12 @@ export const NotDeprecatedEnum = enumType({
members: [
{
name: \\"NOT_DEPRECATED_FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"DEPRECATED_BAR\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.NotDeprecatedEnum.DEPRECATED_BAR is mark as deprecated in a *.proto file.\\",
value: 2
}
Expand All @@ -717,11 +725,13 @@ export const DeprecatedEnum = enumType({
members: [
{
name: \\"DEPRECATED_BAZ\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\",
value: 1
},
{
name: \\"DEPRECATED_QUX\\",
description: \\"\\",
deprecation: \\"testapis.deprecation.DeprecatedEnum is mark as deprecated in a *.proto file.\\",
value: 2
}
Expand Down Expand Up @@ -824,11 +834,13 @@ export const DeprecatedFileEnum = enumType({
members: [
{
name: \\"DEPRECATED_FILE_FOO\\",
description: \\"\\",
deprecation: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\",
value: 1
},
{
name: \\"DEPRECATED_FILE_BAR\\",
description: \\"\\",
deprecation: \\"testapis/deprecation/file_deprecation.proto is mark as deprecated.\\",
value: 2
}
Expand Down Expand Up @@ -1096,10 +1108,12 @@ export const SubpkgEnum = enumType({
members: [
{
name: \\"FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -1205,10 +1219,12 @@ export const SubpkgEnum = enumType({
members: [
{
name: \\"FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -1370,10 +1386,12 @@ export const ParentMessageNestedEnum = enumType({
members: [
{
name: \\"FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -1484,10 +1502,12 @@ export const ParentMessageNestedEnum = enumType({
members: [
{
name: \\"FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -1689,10 +1709,12 @@ export const TestPrefixPrefixedEnum = enumType({
members: [
{
name: \\"PREFIXED_FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"PREFIXED_BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -1908,10 +1930,12 @@ export const TestPrefixPrefixedEnum = enumType({
members: [
{
name: \\"PREFIXED_FOO\\",
description: \\"\\",
value: 1
},
{
name: \\"PREFIXED_BAR\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -2011,6 +2035,7 @@ export const MyEnum = enumType({
members: [
{
name: \\"MY_ENUM_FOO\\",
description: \\"\\",
value: 1
},
{
Expand All @@ -2020,6 +2045,7 @@ export const MyEnum = enumType({
},
{
name: \\"MY_ENUM_BAZ\\",
description: \\"\\",
value: 3
}
]
Expand All @@ -2030,14 +2056,17 @@ export const MyEnumWithoutUnspecified = enumType({
members: [
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_FOO\\",
description: \\"\\",
value: 0
},
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_BAR\\",
description: \\"\\",
value: 1
},
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_BAZ\\",
description: \\"\\",
value: 2
}
]
Expand Down Expand Up @@ -2137,6 +2166,7 @@ export const MyEnum = enumType({
members: [
{
name: \\"MY_ENUM_FOO\\",
description: \\"\\",
value: 1
},
{
Expand All @@ -2146,6 +2176,7 @@ export const MyEnum = enumType({
},
{
name: \\"MY_ENUM_BAZ\\",
description: \\"\\",
value: 3
}
]
Expand All @@ -2156,14 +2187,17 @@ export const MyEnumWithoutUnspecified = enumType({
members: [
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_FOO\\",
description: \\"\\",
value: 0
},
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_BAR\\",
description: \\"\\",
value: 1
},
{
name: \\"MY_ENUM_WITHOUT_UNSPECIFIED_BAZ\\",
description: \\"\\",
value: 2
}
]
Expand Down
11 changes: 5 additions & 6 deletions packages/protoc-gen-nexus/src/dslgen/enumType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ts from "typescript";
import { ProtoEnum, ProtoEnumValue } from "../protoTypes";
import { ProtoEnum, ProtoEnumValue } from "../protogen";
import {
createDeprecationPropertyAssignment,
createDescriptionPropertyAssignment,
createDslExportConstStmt,
gqlTypeName,
isEnumValueForUnspecified,
Expand Down Expand Up @@ -40,7 +41,7 @@ function createEnumTypeDslStmt(en: ProtoEnum): ts.Statement {
ts.factory.createObjectLiteralExpression(
[
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(typeName)),
ts.factory.createPropertyAssignment("description", ts.factory.createStringLiteral(en.description)),
createDescriptionPropertyAssignment(en),
ts.factory.createPropertyAssignment(
"members",
ts.factory.createArrayLiteralExpression(
Expand All @@ -62,11 +63,9 @@ function createEnumValueExpr(ev: ProtoEnumValue): ts.Expression {
return ts.factory.createObjectLiteralExpression(
[
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(ev.name)),
ev.description
? ts.factory.createPropertyAssignment("description", ts.factory.createStringLiteral(ev.description))
: null,
createDescriptionPropertyAssignment(ev),
createDeprecationPropertyAssignment(ev),
ts.factory.createPropertyAssignment("value", ts.factory.createNumericLiteral(ev.tagNumber)),
ts.factory.createPropertyAssignment("value", ts.factory.createNumericLiteral(ev.number)),
].filter(onlyNonNull()),
true // multiline
);
Expand Down
Loading

0 comments on commit f788121

Please sign in to comment.