Composable Types without Unions

Problem

You have relationships between similar types but cannot use Unions. Fauna does not currently support user-defined Union types in GraphQL, but you still need to query for all:

  • entities of a given type,

  • entities with certain properties, regardless of their type.

  • relationships of an entity, regardless of which type it points to.

Discussion

Perhaps you have a schema in mind like the following, where users can collect their favorite movies, shows, and books. A GraphQL Union would make it easy to search for "media" items that could include any Book, Movie, or Show.

# Desired schema, but not valid for Fauna

type User {
  name: String!
  favorites: [MediaItem!]!
  # ...
}

union MediaItem = Movie | Show | Book;

type Movie {
  title: String!
  # ...movie fields
}

type Show {
  title: String!
  # ...TV show fields
}

type Book {
  title: String!
  # ...book fields
}

In this section, several alternative solutions are provided to achieve your goals without user-defined Union types.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!