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