@@ -219,18 +219,19 @@ define one more type that allows us to get to these objects:
219
219
220
220
```
221
221
type Query {
222
- hero: Character
222
+ hero(episode: Episode) : Character
223
223
human(id: String!): Human
224
224
droid(id: String!): Droid
225
225
}
226
226
```
227
227
228
228
This type will be the entry point for the queries described below; it has
229
229
two fields. ` hero ` returns the ` Character ` who is the hero of the
230
- Star Wars trilogy. ` human ` has a new feature in the type system, a query
231
- argument. This field accepts a non-null string as a query argument,
232
- a human's ID, and returns the human with that ID; ` droid ` does the same
233
- for droids.
230
+ Star Wars trilogy; it takes an optional parameter that allows us to fetch the
231
+ hero of a specific episode instead. ` human ` has a new feature in the type
232
+ system, a query argument. This field accepts a non-null string as a query
233
+ argument, a human's ID, and returns the human with that ID; ` droid ` does the
234
+ same for droids.
234
235
235
236
When we package the whole type system together, defining the ` Query ` type
236
237
above as our entry point for queries, this creates a GraphQL Schema.
@@ -554,6 +555,30 @@ Since R2-D2 is a droid, this will return
554
555
}
555
556
```
556
557
558
+ This was particularly useful because ` hero ` was defined to return a ` Character ` ,
559
+ which is an interface; we might want to know what concrete type was actually
560
+ returned. If we instead asked for the hero of episode V:
561
+
562
+ ```
563
+ query CheckTypeOfLuke {
564
+ hero(episode: EMPIRE) {
565
+ __typename
566
+ name
567
+ }
568
+ }
569
+ ```
570
+
571
+ We would find that it was Luke, who is a Human:
572
+
573
+ ``` json
574
+ {
575
+ "hero" : {
576
+ "__typename" : " Human" ,
577
+ "name" : " Luke Skywalker"
578
+ }
579
+ }
580
+ ```
581
+
557
582
As with the type system, this example just scratched the surface of the query
558
583
language. The specification goes into more detail about this topic in the
559
584
"Language" section, and the
0 commit comments