Skip to content

Commit 8ac5838

Browse files
committed
Update README with clarified hero root field
1 parent cbd137f commit 8ac5838

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,19 @@ define one more type that allows us to get to these objects:
214214

215215
```
216216
type Query {
217-
hero: Character
217+
hero(episode: Episode): Character
218218
human(id: String!): Human
219219
droid(id: String!): Droid
220220
}
221221
```
222222

223223
This type will be the entry point for the queries described below; it has
224224
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.
229230

230231
When we package the whole type system together, defining the `Query` type
231232
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
549550
}
550551
```
551552

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+
552577
As with the type system, this example just scratched the surface of the query
553578
language. The specification goes into more detail about this topic in the
554579
"Language" section, and the

0 commit comments

Comments
 (0)