Skip to main content

Getting started with your first queries

Say you run a fantastic movie community like The Movie Database. Your users can write reviews on these movies.

Your first query

You wish to show all reviews on a movie detail page, say Fight Club. The identifier of Fight Club on The Movie Database is 550-fight-club.

query MovieReviews {
movies(where: { identifier: "550-fight-club" }) {
reviews {
rating
content
}
}
}

Sorting

Now you wish to show the latest reviews first. Add an additional field created to verify this.

query MovieReviewsOrdered {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }) {
rating
content
created
}
}
}

Counting

Say you want to find out how many reviews were written on this movie.

query MovieReviewsWithCount {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }) {
rating
content
created
}
reviewsAggregations {
COUNT
}
}
}

Pagination

Since there are more than 10 reviews on this movie, you wish to show only the first 10 and add pagination to the rest. Add first and skip as arguments.

query MovieReviewsWithCountFirstTen {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }, first: 10, skip: 0) {
rating
content
created
}
reviewsAggregations {
COUNT
}
}
}

Comments and likes on reviews

Movie reviews can receive comments and likes. You wish to display a count of the comments and likes for each review.

query MovieReviewsWithCommentsLikes {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }, first: 10, skip: 0) {
rating
content
comments {
content
}
likesAggregations {
COUNT
}
}
reviewsAggregations {
COUNT
}
}
}