Skip to content

Commit 0299c2e

Browse files
author
Sashko Stubailo
committed
Reformat data, add search section
1 parent d729c5b commit 0299c2e

File tree

3 files changed

+158
-330
lines changed

3 files changed

+158
-330
lines changed

site/docs/Learn-Queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,4 @@ In this query, the `hero` field returns the type `Character`, which might be eit
228228

229229
To ask for a field on the concrete type, you need to use an _inline fragment_ with a type condition. Because the first fragment is labeled as `... on Droid`, the `primaryFunction` field will only be executed if the `Character` returned from `hero` is of the `Droid` type. Similarly for the `homePlanet` field for the `Human` type.
230230

231-
Named fragments can also be used in the same way, since a named fragment always has a type condition attached.
231+
Named fragments can also be used in the same way, since a named fragment always has a type attached.

site/docs/Learn-Schema.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,30 @@ Learn more about this in the [inline fragments](XXX) section in the query guide.
285285

286286
Union types are very similar to interfaces, but they don't get to specify any common fields between the types.
287287

288-
XXX no example in SWAPI
289-
290288
```graphql
291-
union SearchResult = Character | Starship
289+
union SearchResult = Human | Droid | Starship
292290
```
293291

294-
In this case, if you query a field that returns the `SearchResult` union type, you need to use a conditional fragment to be able to query any fields at all.
292+
Wherever we return a `SearchResult` type in our schema, we might get a `Human`, a `Droid`, or a `Starship`. Note that members of a union type need to be concrete object types; you can't create a union type out of interfaces or other unions.
293+
294+
In this case, if you query a field that returns the `SearchResult` union type, you need to use a conditional fragment to be able to query any fields at all:
295+
296+
```graphql
297+
# { "graphiql": true}
298+
{
299+
search(text: "an") {
300+
... on Human {
301+
name
302+
height
303+
}
304+
... on Droid {
305+
name
306+
primaryFunction
307+
}
308+
... on Starship {
309+
name
310+
length
311+
}
312+
}
313+
}
314+
```

0 commit comments

Comments
 (0)