diff --git a/site/learn/Learn-Schema.md b/site/learn/Learn-Schema.md index db6cdde821..40a5b7ced5 100644 --- a/site/learn/Learn-Schema.md +++ b/site/learn/Learn-Schema.md @@ -311,6 +311,7 @@ In this case, if you query a field that returns the `SearchResult` union type, y # { "graphiql": true} { search(text: "an") { + __typename ... on Human { name height @@ -327,6 +328,33 @@ In this case, if you query a field that returns the `SearchResult` union type, y } ``` +The `__typename` field resolves to a `String` which lets you differentiate different data types from each other on the client. + +Also, in this case, since `Human` and `Droid` share a common interface (`Character`), you can query their common fields in one place rather than having to repeat the same fields across multiple types: + +```graphql +{ + search(text: "an") { + __typename + ... on Character { + name + } + ... on Human { + height + } + ... on Droid { + primaryFunction + } + ... on Starship { + name + length + } + } +} +``` + +Note that `name` is still specified on `Starship` because otherwise it wouldn't show up in the results given that `Starship` is not a `Character`! + ### Input types So far, we've only talked about passing scalar values, like enums or strings, as arguments into a field. But you can also easily pass complex objects. This is particularly valuable in the case of mutations, where you might want to pass in a whole object to be created. In the GraphQL schema language, input types look exactly the same as regular object types, but with the keyword `input` instead of `type`: