File tree 2 files changed +39
-0
lines changed 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -488,6 +488,9 @@ func parseUnionDef(l *common.Lexer) *ast.Union {
488
488
489
489
union .Directives = common .ParseDirectives (l )
490
490
l .ConsumeToken ('=' )
491
+ if l .Peek () == '|' {
492
+ l .ConsumeToken ('|' )
493
+ }
491
494
union .TypeNames = []string {l .ConsumeIdent ()}
492
495
for l .Peek () == '|' {
493
496
l .ConsumeToken ('|' )
Original file line number Diff line number Diff line change @@ -1124,6 +1124,42 @@ func TestInterfaceImplementsInterface(t *testing.T) {
1124
1124
return nil
1125
1125
},
1126
1126
},
1127
+ {
1128
+ name : "Unions can be defined with a leading pipe" ,
1129
+ sdl : `
1130
+ type Named {
1131
+ name: String!
1132
+ }
1133
+ type Numbered {
1134
+ num: Int!
1135
+ }
1136
+ union Item1 =
1137
+ | Named
1138
+ | Numbered
1139
+ union Item2 = | Named | Numbered
1140
+ ` ,
1141
+ validateSchema : func (s * ast.Schema ) error {
1142
+ for _ , itemName := range []string {"Item1" , "Item2" } {
1143
+ typ , ok := s .Types [itemName ].(* ast.Union )
1144
+ if ! ok {
1145
+ return fmt .Errorf ("type %q not found" , "Item" )
1146
+ }
1147
+ if len (typ .UnionMemberTypes ) != 2 {
1148
+ return fmt .Errorf ("Expected 2 possible types, but instead got %d types" , len (typ .UnionMemberTypes ))
1149
+ }
1150
+ posible := map [string ]struct {}{
1151
+ "Named" : {},
1152
+ "Numbered" : {},
1153
+ }
1154
+ for _ , pt := range typ .UnionMemberTypes {
1155
+ if _ , ok := posible [pt .Name ]; ! ok {
1156
+ return fmt .Errorf ("Unexpected possible type %q" , pt .Name )
1157
+ }
1158
+ }
1159
+ }
1160
+ return nil
1161
+ },
1162
+ },
1127
1163
} {
1128
1164
t .Run (tt .name , func (t * testing.T ) {
1129
1165
s , err := schema .ParseSchema (tt .sdl , tt .useStringDescriptions )
You can’t perform that action at this time.
0 commit comments