hydra
v3
v3
  • Hydra
  • Hydra CLI
  • Hydra Indexer
  • Hydra Indexer Gateway
  • Hydra Processor
  • Hydra Typegen
  • Overview
    • Query Node Manifest
    • Graphql Queries
    • Pagination
    • Sorting
    • Mappings
      • Context interfaces
      • Mapping Filters
      • Mapping Types
    • Schema
      • The Goodies
      • Entities
      • Enums
      • Interfaces
      • Algebraic types
      • Full-text queries
      • Entity Relationships
      • Cross filtering
      • Variant relations
    • Architecture
  • Install Hydra
  • Migration to Hydra v2
  • What's new in Hydra v3
  • FAQ
  • Quickstart
Powered by GitBook
On this page

Was this helpful?

  1. Overview
  2. Schema

Algebraic types

One can construct complex types by defining unions of special non-entity type definitions decorated with @variant. The resulting complex type is mapped into JSON at the database level and should be prefixed with _json in when queried through the API. Here is an example

type Miserable @variant {
  hates: String!
}

type HappyPoor @variant {
  isMale: Boolean
}

union Poor = HappyPoor | Miserable

type MiddleClass @variant {
  father: Poor
  mother: Poor
}

type Rich @variant {
  bank: String!
}

union Status = Rich | MiddleClass | HappyPoor | Miserable

type Account @entity {
  status: Status!
}
query {
    accounts(limit: 5, orderBy: about_ASC, where: { status_json: { father: { isMale_eq: true }} }) {
    about
    status {
      __typename 
      ... on MiddleClass {
        father {
          ... on HappyPoor {
            isMale
          }
          ... on Miserable {
            hates
          }
        }
      }
    }
  }
}
PreviousInterfacesNextFull-text queries

Last updated 3 years ago

Was this helpful?

The resulting API will support and type resolutions:

inline fragments