Interfaces

Extract interfaces and query multiple types in a single query

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 interface type and inline fragments in the output schema. For example, let us define the following input schema:

interface Profile {
    about: String!
}

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

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

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
    }
  }
}

Last updated