Overview - Graphql

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 two types of of queries generated for each type.


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 two queries generated for Post and two 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]

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. You can look at all the queries that are generated by using any GraphQL client such as Insomnia or GraphQL playground.

This is a companion discussion topic for the original entry at https://dgraph.io/docs/graphql/queries/queries-overview/