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

Interfaces

Extract interfaces and query multiple types in a single query

PreviousEnumsNextAlgebraic types

Last updated 4 years ago

Was this helpful?

Interfaces are useful when several entity types share some set of properties and one would like to have an aggregated result when such a common property is queried.

This is achieved through the natively supported GraphQL type and in the output schema. For example, let us define the following input schema:

interface Profile @entity {
    about: String!
}

type Member implements Profile @entity {
    about: String!
    handle: String!
}

type Account implements Profile @entity {
    about: String!
    accountId: Bytes   
}

Note that interfaces should be decorated with @entity and all the subclasses must explicitly define the inherited fields (otherwise an error will be thrown during the codegen).

The output schema will support a query by about which puts together Member and Account types. Note that orderBy is also supported for the inherited properties as well as OpenCRUD.

query {
  profiles(limit: 5, offset: 5, orderBy: about_ASC, where: { about_eq: "joystreamer" }) {
    about
    __typename 
    ... on Member {
      handle
    }
    ... on Account {
      accountId
    }
  }
}
interface
inline fragments