Queries

This is the documentation of the GraphQL Library version 7. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS.

Type definitions

Queries on this page assume the following type definitions:

type Post @node {
    id: ID! @id
    content: String!
    creators: [User!]! @relationship(type: "HAS_POST", direction: IN, properties: "PostedAt")
    createdAt: DateTime!
}

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

type PostedAt @relationshipProperties {
    date: DateTime
}

For which the following query fields are generated:

type Query {
  postsConnection(first: Int, after: String, where: PostWhere, sort: [PostSort!]): PostsConnection!
  posts(where: PostWhere, limit: Int, offset: Int, sort: [PostSort!]): [Post!]!
  usersConnection(first: Int, after: String, where: UserWhere, sort: [UserSort!]): UsersConnection!
  users(where: UserWhere, limit: Int, offset: Int, sort: [UserSort!]): [User!]!
}

Writing queries

Based on the type definitions, here are two examples of how to write queries for reading or retrieving values:

Return all User nodes from their ID and name
query {
    users {
        id
        name
    }
}
Query User with name "Jane Smith" and their posts
query {
  users(where: { name: { eq: "Jane Smith" } }) {
    id
    name
    posts {
      content
    }
  }
}