Skip to content

Commit cf60418

Browse files
committed
Merge branch 'master' of github.com:facebook/graphql
2 parents af5c288 + df798c4 commit cf60418

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
@@ -219,18 +219,19 @@ define one more type that allows us to get to these objects:
219219

220220
```
221221
type Query {
222-
hero: Character
222+
hero(episode: Episode): Character
223223
human(id: String!): Human
224224
droid(id: String!): Droid
225225
}
226226
```
227227

228228
This type will be the entry point for the queries described below; it has
229229
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.
234235

235236
When we package the whole type system together, defining the `Query` type
236237
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
554555
}
555556
```
556557

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

0 commit comments

Comments
 (0)