44import java .util .ArrayList ;
55import java .util .List ;
66
7- import static graphql .Assert .assertNotNull ;
7+ import static graphql .Assert .* ;
88
99public class GraphQLUnionType implements GraphQLType , GraphQLOutputType , GraphQLCompositeType , GraphQLUnmodifiedType , GraphQLNullableType {
1010
1111 private final String name ;
1212 private final String description ;
13- private List <GraphQLType > types = new ArrayList <GraphQLType >();
13+ private List <GraphQLObjectType > types = new ArrayList <GraphQLObjectType >();
1414 private final TypeResolver typeResolver ;
1515
1616
17- public GraphQLUnionType (String name , String description , List <GraphQLType > types , TypeResolver typeResolver ) {
17+ public GraphQLUnionType (String name , String description , List <GraphQLObjectType > types , TypeResolver typeResolver ) {
1818 assertNotNull (name , "name can't be null" );
1919 assertNotNull (types , "types can't be null" );
20+ assertNotEmpty (types , "A Union type must define one or more member types." );
2021 assertNotNull (typeResolver , "typeResolver can't be null" );
2122 this .name = name ;
2223 this .description = description ;
@@ -25,8 +26,8 @@ public GraphQLUnionType(String name, String description, List<GraphQLType> types
2526 }
2627
2728
28- public List <GraphQLType > getTypes () {
29- return new ArrayList <GraphQLType >(types );
29+ public List <GraphQLObjectType > getTypes () {
30+ return new ArrayList <GraphQLObjectType >(types );
3031 }
3132
3233 public TypeResolver getTypeResolver () {
@@ -49,7 +50,7 @@ public static Builder newUnionType() {
4950 public static class Builder {
5051 private String name ;
5152 private String description ;
52- private List <GraphQLType > types = new ArrayList <GraphQLType >();
53+ private List <GraphQLObjectType > types = new ArrayList <GraphQLObjectType >();
5354 private TypeResolver typeResolver ;
5455
5556 public Builder name (String name ) {
@@ -69,14 +70,14 @@ public Builder typeResolver(TypeResolver typeResolver) {
6970 }
7071
7172
72- public Builder possibleType (GraphQLType type ) {
73+ public Builder possibleType (GraphQLObjectType type ) {
7374 assertNotNull (type , "possible type can't be null" );
7475 types .add (type );
7576 return this ;
7677 }
7778
78- public Builder possibleTypes (GraphQLType ... type ) {
79- for (GraphQLType graphQLType : type ) {
79+ public Builder possibleTypes (GraphQLObjectType ... type ) {
80+ for (GraphQLObjectType graphQLType : type ) {
8081 possibleType (graphQLType );
8182 }
8283 return this ;
0 commit comments