Queries

Each node defined in type definitions will have two Query fields generated for it - one for querying data and one for counting data.

The examples in this chapter will use the following type definitions:

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

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

For which the following Query fields will be generated:

type Query {
    posts(where: PostWhere, options: PostOptions): [Post!]!
    postsCount(where: PostWhere): Int!
    users(where: UserWhere, options: UserOptions): [User!]!
    usersCount(where: UserWhere): Int!
}

Query

Each field for querying data accepts two arguments:

Querying for all User nodes

The following Query will return all User nodes, returning their ID and name.

query {
    users {
        id
        name
    }
}

Query for user with name "Jane Smith" and their posts

The following Query will return all Users, returning the content which they have posted.

query {
    users(where: { name: "Jane Smith" }) {
        id
        name
        posts {
            content
        }
    }
}

Count

Counting all User nodes

The following Query will count all User nodes:

query {
    usersCount
}

Counting User nodes where name starts with "J"

query {
    usersCount(where: { name_STARTS_WITH: "J" })
}