Files
main.tsmain
What you'll learn
- Declare an interface with @InterfaceType() and object types that implement it, inheriting its fields
- Query a list of an interface with inline fragments and __typename
- Resolve a field once for every implementation with a resolver for the interface
- Declare a union with createUnionType(), and tell plain objects apart with resolveType
Press Run tests to start the app. Its log appears here.Graded endpoints
The shared fields are asked for once; breed and size through inline fragments on each type; __typename says what resolveType decided
summary is resolved once, on the interface, for cats and dogs alike; age came from the interface too
GraphQL refuses it: on an Animal, breed needs a fragment on Cat
The union holds cats, dogs and owners; a fragment on the Animal interface covers both animals at once
Animal is an interface implemented by Cat and Dog; SearchResult a union of three types