Skip to content

Commit 42029a7

Browse files
committed
star wars schema
1 parent f9e7a7d commit 42029a7

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

src/main/java/graphql/schema/GraphQLSelfReference.java renamed to src/main/java/graphql/schema/GraphQLTypeReference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package graphql.schema;
22

33

4-
public class GraphQLSelfReference implements GraphQLType {
4+
public class GraphQLTypeReference implements GraphQLType {
55

66
private final String name;
77

8-
public GraphQLSelfReference(String name) {
8+
public GraphQLTypeReference(String name) {
99
this.name = name;
1010
}
1111

src/test/java/grapqhl/StarWarsSchema.java

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package grapqhl;
22

33

4-
import graphql.Scalars;
54
import graphql.schema.*;
65

76
import static graphql.Scalars.GraphQLString;
87
import static graphql.schema.GraphQLEnumType.newEnum;
8+
import static graphql.schema.GraphQLFieldArgument.newFieldArgument;
99
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
1010
import static graphql.schema.GraphQLInterfaceType.newInterface;
11+
import static graphql.schema.GraphQLObjectType.newObject;
1112

1213
public class StarWarsSchema {
1314

@@ -37,7 +38,7 @@ public class StarWarsSchema {
3738
.field(newFieldDefinition()
3839
.name("friends")
3940
.description("The friends of the character, or an empty list if they have none.")
40-
.type(new GraphQLList(new GraphQLSelfReference("Character")))
41+
.type(new GraphQLList(new GraphQLTypeReference("Character")))
4142
.build())
4243
.field(newFieldDefinition()
4344
.name("appearsIn")
@@ -46,4 +47,90 @@ public class StarWarsSchema {
4647
.build())
4748
.build();
4849

50+
GraphQLObjectType humanType = newObject()
51+
.name("Human")
52+
.description("A humanoid creature in the Star Wars universe.")
53+
.withInterface(characterInterface)
54+
.field(newFieldDefinition()
55+
.name("id")
56+
.description("The id of the human.")
57+
.type(new GraphQLNonNull(GraphQLString))
58+
.build())
59+
.field(newFieldDefinition()
60+
.name("name")
61+
.description("The name of the human.")
62+
.type(GraphQLString)
63+
.build())
64+
.field(newFieldDefinition()
65+
.name("friends")
66+
.description("The friends of the human, or an empty list if they have none.")
67+
.type(new GraphQLList(characterInterface))
68+
.build())
69+
.field(newFieldDefinition()
70+
.name("appearsIn")
71+
.description("Which movies they appear in.")
72+
.type(new GraphQLList(episodeEnum))
73+
.build())
74+
.field(newFieldDefinition()
75+
.name("homePlanet")
76+
.description("The home planet of the human, or null if unknown.")
77+
.type(GraphQLString)
78+
.build())
79+
.build();
80+
81+
GraphQLObjectType droidType = newObject()
82+
.name("Droid")
83+
.description("A mechanical creature in the Star Wars universe.")
84+
.withInterface(characterInterface)
85+
.field(newFieldDefinition()
86+
.name("id")
87+
.description("The id of the droid.")
88+
.type(new GraphQLNonNull(GraphQLString))
89+
.build())
90+
.field(newFieldDefinition()
91+
.name("name")
92+
.description("The name of the droid.")
93+
.type(GraphQLString)
94+
.build())
95+
.field(newFieldDefinition()
96+
.name("friends")
97+
.description("The friends of the droid, or an empty list if they have none.")
98+
.type(new GraphQLList(characterInterface))
99+
.build())
100+
.field(newFieldDefinition()
101+
.name("appearsIn")
102+
.description("Which movies they appear in.")
103+
.type(new GraphQLList(episodeEnum))
104+
.build())
105+
.field(newFieldDefinition()
106+
.name("primaryFunction")
107+
.description("The primary function of the droid.")
108+
.type(GraphQLString)
109+
.build())
110+
.build();
111+
112+
GraphQLObjectType queryType = newObject()
113+
.name("QueryType")
114+
.field(newFieldDefinition()
115+
.name("hero")
116+
.type(characterInterface)
117+
.build())
118+
.field(newFieldDefinition()
119+
.name("human")
120+
.type(humanType)
121+
.argument(newFieldArgument()
122+
.name("id")
123+
.type(new GraphQLNonNull(GraphQLString))
124+
.build())
125+
.build())
126+
.field(newFieldDefinition()
127+
.name("droid")
128+
.type(droidType)
129+
.argument(newFieldArgument()
130+
.name("id")
131+
.type(new GraphQLNonNull(GraphQLString))
132+
.build())
133+
.build())
134+
.build();
135+
49136
}

0 commit comments

Comments
 (0)