Skip to content

Commit

Permalink
feat: support graphql.object_type.squash_union option
Browse files Browse the repository at this point in the history
  • Loading branch information
izumin5210 authored Dec 31, 2020
1 parent 83b862a commit 57d947e
Show file tree
Hide file tree
Showing 13 changed files with 609 additions and 33 deletions.
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/@testapis/proto/src/testapis/extensions/extensions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ message PrefixedMessage {
string body = 1;
}

message InnerMessage2 {
string body = 1;
}

message SquashedMessage {
option (graphql.object_type).squash_union = true;

oneof squashed_message {
InnerMessage oneof_ignored_field = 1;
InnerMessage2 oneof_ignored_field_2 = 2;
}
}

// Output only.
uint64 id = 1;
string body = 2;
Expand All @@ -49,6 +62,7 @@ message PrefixedMessage {
OutputOnlyMessage output_only_message = 8;
InputOnlyMessage input_only_message = 9;
IgnoredEnum ignored_enum = 10;
SquashedMessage squashed_message = 11;
}

enum PrefixedEnum {
Expand Down
16 changes: 16 additions & 0 deletions packages/protoc-gen-nexus/include/graphql/schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ extend google.protobuf.FileOptions {

message GraphqlObjectTypeOptions {
bool ignore = 1;
// If `squash_union` is true, the message is converted to `union` type.
//
// ```proto
// message Content {
// option (graphql.object_type).squash_union = true;
// oneof content {
// Blog blog = 2;
// Video video = 2;
// }
// }
// ```
//
// ```grahpql
// union Content = Blog | Video
// ```
bool squash_union = 2;
}

message GraphqlInputObjectTypeOptions {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,121 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`schema generation with native protobuf can make GraphQL schema from generated DSLs: schema.graphql 1`] = `
"### This file was generated by Nexus Schema
### Do not make changes to this file directly
type Query {
ok: Boolean!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixInputOnlyMessageInput {
\\"\\"\\"\\"\\"\\"
body: String!
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
}
\\"\\"\\"\\"\\"\\"
type TestPrefixOutputOnlyMessage {
\\"\\"\\"\\"\\"\\"
body: String!
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
}
\\"\\"\\"\\"\\"\\"
enum TestPrefixPrefixedEnum {
PREFIXED_BAR
PREFIXED_FOO
}
\\"\\"\\"\\"\\"\\"
type TestPrefixPrefixedMessage {
\\"\\"\\"\\"\\"\\"
body: String!
\\"\\"\\"Output only.\\"\\"\\"
id: String!
\\"\\"\\"\\"\\"\\"
outputOnlyMessage: TestPrefixOutputOnlyMessage
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
\\"\\"\\"\\"\\"\\"
squashedMessage: TestPrefixPrefixedMessageSquashedMessage
}
\\"\\"\\"\\"\\"\\"
type TestPrefixPrefixedMessageInnerMessage {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
type TestPrefixPrefixedMessageInnerMessage2 {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageInnerMessage2Input {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageInnerMessageInput {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageInput {
\\"\\"\\"\\"\\"\\"
body: String!
\\"\\"\\"\\"\\"\\"
inputOnlyMessage: TestPrefixInputOnlyMessageInput
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
\\"\\"\\"\\"\\"\\"
squashedMessage: TestPrefixPrefixedMessageSquashedMessageInput
}
\\"\\"\\"\\"\\"\\"
union TestPrefixPrefixedMessageSquashedMessage = TestPrefixPrefixedMessageInnerMessage | TestPrefixPrefixedMessageInnerMessage2
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageSquashedMessageInput {
\\"\\"\\"\\"\\"\\"
oneofIgnoredField: TestPrefixPrefixedMessageInnerMessageInput
\\"\\"\\"\\"\\"\\"
oneofIgnoredField2: TestPrefixPrefixedMessageInnerMessage2Input
}
"
`;

exports[`schema generation with native protobuf squashed union 1`] = `
Object {
"data": Object {
"test": Object {
"squashedMessage": Object {
"body": "field 2",
},
},
},
}
`;

exports[`schema generation with protobufjs can make GraphQL schema from generated DSLs: schema.graphql 1`] = `
"### This file was generated by Nexus Schema
### Do not make changes to this file directly
Expand Down Expand Up @@ -46,6 +162,9 @@ type TestPrefixPrefixedMessage {
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
\\"\\"\\"\\"\\"\\"
squashedMessage: TestPrefixPrefixedMessageSquashedMessage
}
\\"\\"\\"\\"\\"\\"
Expand All @@ -54,6 +173,18 @@ type TestPrefixPrefixedMessageInnerMessage {
body: String!
}
\\"\\"\\"\\"\\"\\"
type TestPrefixPrefixedMessageInnerMessage2 {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageInnerMessage2Input {
\\"\\"\\"\\"\\"\\"
body: String!
}
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageInnerMessageInput {
\\"\\"\\"\\"\\"\\"
Expand All @@ -70,6 +201,33 @@ input TestPrefixPrefixedMessageInput {
\\"\\"\\"\\"\\"\\"
prefixedEnum: TestPrefixPrefixedEnum
\\"\\"\\"\\"\\"\\"
squashedMessage: TestPrefixPrefixedMessageSquashedMessageInput
}
\\"\\"\\"\\"\\"\\"
union TestPrefixPrefixedMessageSquashedMessage = TestPrefixPrefixedMessageInnerMessage | TestPrefixPrefixedMessageInnerMessage2
\\"\\"\\"\\"\\"\\"
input TestPrefixPrefixedMessageSquashedMessageInput {
\\"\\"\\"\\"\\"\\"
oneofIgnoredField: TestPrefixPrefixedMessageInnerMessageInput
\\"\\"\\"\\"\\"\\"
oneofIgnoredField2: TestPrefixPrefixedMessageInnerMessage2Input
}
"
`;

exports[`schema generation with protobufjs squashed union 1`] = `
Object {
"data": Object {
"test": Object {
"squashedMessage": Object {
"body": "field 2",
},
},
},
}
`;
Loading

0 comments on commit 57d947e

Please sign in to comment.