You are looking at the docs for the unreleased master branch of Dgraph. The latest version is v20.11.
Report Issue Edit Page

Overview

How to use queries to fetch data from Dgraph.

Dgraph automatically generates GraphQL queries for each type that you define in your schema. There are three types of queries generated for each type.

Example

type Post {
    id: ID!
    title: String! @search
    text: String
    score: Float @search
    completed: Boolean @search
    datePublished: DateTime @search(by: [year])
    author: Author!
}

type Author {
    id: ID!
    name: String! @search
    posts: [Post!]
    friends: [Author]
}

With the above schema, there would be three queries generated for Post and three for Author. Here are the queries that are generated for the Post type:

getPost(postID: ID!): Post
queryPost(filter: PostFilter, order: PostOrder, first: Int, offset: Int): [Post]
aggregatePost(filter: PostFilter): PostAggregateResult

The first query allows you to fetch a post and its related fields given an ID. The second query allows you to fetch a list of posts based on some filters, sorting and pagination parameters. The third query allows you to fetch aggregate parameters like count of nodes based on filters.

Additionally, a check<Type>Password query is generated for types that have been specified with a @secret directive.

You can look at all the queries that are generated by using any GraphQL client such as Insomnia or GraphQL playground.

Continue the conversation on Discuss.