Interfaces and unions — GraphQL · NestJS

Fields that hold more than one kind of object: an Animal interface that cats and dogs implement, with a field resolved once for both, a search that answers a union of cats, dogs and owners, and the resolveType functions that tell plain objects apart.

What you will learn

Read the theory for Interfaces and unions

All GraphQL lessons

All NestJS courses

loading types…

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