Queries and aggregations

Each node defined in type definitions has two query fields generated for it: one for querying data and another one for aggregating it. Each of these fields, by their part, accepts two arguments used for filtering, sorting, and pagination.

This section addresses the following topics:

  • Queries - How to read or fetch values.

  • Aggregations - How to combine lists of types from different sources into a single list.

  • Filtering - How to filter query results to find objects.

  • Sorting - How to sort query results by each individual field.

All examples featured in this section use the following type definitions:

type Post {
    id: ID! @id
    content: String!
    creator: User! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
    createdAt: DateTime!

type User {
    id: ID! @id
    name: String!
    posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT, properties: "PostedAt")
    friends: [User!]! @relationship(type: "FRIENDS_WITH", direction: OUT)

interface PostedAt @relationshipProperties {
    date: DateTime

For which the following query fields are generated:

type Query {
    posts(where: PostWhere, options: PostOptions): [Post!]!
    postsAggregate(where: PostWhere): PostAggregationSelection!

    users(where: UserWhere, options: UserOptions): [User!]!
    usersAggregate(where: UserWhere): UserAggregationSelection!