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
.
- GraphQL request
- Response
query MovieReviews {
movies(where: { identifier: "550-fight-club" }) {
reviews {
rating
content
}
}
}
{
"data": {
"movies": [
{
"reviews": [
{
"rating": 5,
"content": "There are movies you hate, there are movies you love, and there are movies that changed your life."
},
{
"rating": 4,
"content": "Okay yeah I still think this is overrated. Still love u tho Fincher"
},
{
"rating": 5,
"content": "I look around, I look around, I see a lot of reviews for this classic. Which means a lot of people have been breaking the first two rules of Fight Club. Now if you are reading this then this warning is for you. Every word you read of this useless fine print is another second off your life. Don't you have other things to do? Is your life so empty that you honestly can't think of a better way to spend these moments? Or are you so impressed with authority that you give respect & credence to all that claim it? Do you read everything you are supposed to read? Do you think everything you are supposed to think? Buy what you are told you should want? Get out of your apartment. Meet a member of the opposite sex. Stop the excessive shopping & masturbation. Quit your job. Start a fight. Prove you're alive. If you don't claim your humanity, you will become a statistic. You have been warned."
},
{
"rating": 5,
"content": "Ikea boy"
},
{
"rating": 5,
"content": "This was not at ALL what I expected."
},
{
"rating": 5,
"content": "Not allowed to talk about this one thems the rules"
},
{
"rating": 5,
"content": "The other day I told my friend that Fight Club is my favorite movie. She replied \"I hate Fight Club. I hate boxing movies.\" I don't think that she's actually seen Fight Club."
},
{
"rating": 1,
"content": "Unfortunately the contents are so thin that the interiors of his tale vanish very quickly."
},
{
"rating": 4,
"content": "This is one of the most unique films I have ever seen. In addition to presenting a rather fresh take on life, FC also presents its material in a fresh way."
},
{
"rating": 4,
"content": "RE-TEACH MEN WHAT SATIRE IS"
},
{
"rating": 5,
"content": "Narrator, tyler, marla: the unholy trinity"
},
{
"rating": 5,
"content": "brad pitt. omg brad pitt."
}
]
}
]
}
}
Sorting
Now you wish to show the latest reviews first. Add an additional field created
to verify this.
- GraphQL request
- Response
query MovieReviewsOrdered {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }) {
rating
content
created
}
}
}
{
"data": {
"movies": [
{
"reviews": [
{
"rating": 5,
"content": "There are movies you hate, there are movies you love, and there are movies that changed your life.",
"created": "2020-01-27T17:21:55.080Z"
},
{
"rating": 4,
"content": "RE-TEACH MEN WHAT SATIRE IS",
"created": "2020-01-27T17:21:28.724Z"
},
{
"rating": 5,
"content": "brad pitt. omg brad pitt.",
"created": "2020-01-27T17:20:56.141Z"
},
{
"rating": 5,
"content": "Ikea boy",
"created": "2020-01-27T17:20:39.731Z"
},
{
"rating": 5,
"content": "Narrator, tyler, marla: the unholy trinity",
"created": "2020-01-27T17:19:49.614Z"
},
{
"rating": 4,
"content": "Okay yeah I still think this is overrated. Still love u tho Fincher",
"created": "2020-01-27T17:19:27.442Z"
},
{
"rating": 5,
"content": "This was not at ALL what I expected.",
"created": "2020-01-27T17:19:00.217Z"
},
{
"rating": 5,
"content": "Not allowed to talk about this one thems the rules",
"created": "2020-01-27T17:18:28.748Z"
},
{
"rating": 5,
"content": "The other day I told my friend that Fight Club is my favorite movie. She replied \"I hate Fight Club. I hate boxing movies.\" I don't think that she's actually seen Fight Club.",
"created": "2020-01-27T17:17:42.854Z"
},
{
"rating": 5,
"content": "I look around, I look around, I see a lot of reviews for this classic. Which means a lot of people have been breaking the first two rules of Fight Club. Now if you are reading this then this warning is for you. Every word you read of this useless fine print is another second off your life. Don't you have other things to do? Is your life so empty that you honestly can't think of a better way to spend these moments? Or are you so impressed with authority that you give respect & credence to all that claim it? Do you read everything you are supposed to read? Do you think everything you are supposed to think? Buy what you are told you should want? Get out of your apartment. Meet a member of the opposite sex. Stop the excessive shopping & masturbation. Quit your job. Start a fight. Prove you're alive. If you don't claim your humanity, you will become a statistic. You have been warned.",
"created": "2020-01-27T16:56:21.794Z"
},
{
"rating": 4,
"content": "This is one of the most unique films I have ever seen. In addition to presenting a rather fresh take on life, FC also presents its material in a fresh way.",
"created": "2019-01-24T17:14:49.337Z"
},
{
"rating": 1,
"content": "Unfortunately the contents are so thin that the interiors of his tale vanish very quickly.",
"created": "2019-01-23T17:14:49.337Z"
}
]
}
]
}
}
Counting
Say you want to find out how many reviews were written on this movie.
- GraphQL request
- Response
query MovieReviewsWithCount {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }) {
rating
content
created
}
reviewsAggregations {
COUNT
}
}
}
{
"data": {
"movies": [
{
"reviews": [
{
"rating": 5,
"content": "There are movies you hate, there are movies you love, and there are movies that changed your life.",
"created": "2020-01-27T17:21:55.080Z"
},
{
"rating": 4,
"content": "RE-TEACH MEN WHAT SATIRE IS",
"created": "2020-01-27T17:21:28.724Z"
},
{
"rating": 5,
"content": "brad pitt. omg brad pitt.",
"created": "2020-01-27T17:20:56.141Z"
},
{
"rating": 5,
"content": "Ikea boy",
"created": "2020-01-27T17:20:39.731Z"
},
{
"rating": 5,
"content": "Narrator, tyler, marla: the unholy trinity",
"created": "2020-01-27T17:19:49.614Z"
},
{
"rating": 4,
"content": "Okay yeah I still think this is overrated. Still love u tho Fincher",
"created": "2020-01-27T17:19:27.442Z"
},
{
"rating": 5,
"content": "This was not at ALL what I expected.",
"created": "2020-01-27T17:19:00.217Z"
},
{
"rating": 5,
"content": "Not allowed to talk about this one thems the rules",
"created": "2020-01-27T17:18:28.748Z"
},
{
"rating": 5,
"content": "The other day I told my friend that Fight Club is my favorite movie. She replied \"I hate Fight Club. I hate boxing movies.\" I don't think that she's actually seen Fight Club.",
"created": "2020-01-27T17:17:42.854Z"
},
{
"rating": 5,
"content": "I look around, I look around, I see a lot of reviews for this classic. Which means a lot of people have been breaking the first two rules of Fight Club. Now if you are reading this then this warning is for you. Every word you read of this useless fine print is another second off your life. Don't you have other things to do? Is your life so empty that you honestly can't think of a better way to spend these moments? Or are you so impressed with authority that you give respect & credence to all that claim it? Do you read everything you are supposed to read? Do you think everything you are supposed to think? Buy what you are told you should want? Get out of your apartment. Meet a member of the opposite sex. Stop the excessive shopping & masturbation. Quit your job. Start a fight. Prove you're alive. If you don't claim your humanity, you will become a statistic. You have been warned.",
"created": "2020-01-27T16:56:21.794Z"
},
{
"rating": 4,
"content": "This is one of the most unique films I have ever seen. In addition to presenting a rather fresh take on life, FC also presents its material in a fresh way.",
"created": "2019-01-24T17:14:49.337Z"
},
{
"rating": 1,
"content": "Unfortunately the contents are so thin that the interiors of his tale vanish very quickly.",
"created": "2019-01-23T17:14:49.337Z"
}
],
"reviewsAggregations": {
"COUNT": 12
}
}
]
}
}
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.
- GraphQL request
- Response
query MovieReviewsWithCountFirstTen {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }, first: 10, skip: 0) {
rating
content
created
}
reviewsAggregations {
COUNT
}
}
}
{
"data": {
"movies": [
{
"reviews": [
{
"rating": 5,
"content": "There are movies you hate, there are movies you love, and there are movies that changed your life.",
"created": "2020-01-27T17:21:55.080Z"
},
{
"rating": 4,
"content": "RE-TEACH MEN WHAT SATIRE IS",
"created": "2020-01-27T17:21:28.724Z"
},
{
"rating": 5,
"content": "brad pitt. omg brad pitt.",
"created": "2020-01-27T17:20:56.141Z"
},
{
"rating": 5,
"content": "Ikea boy",
"created": "2020-01-27T17:20:39.731Z"
},
{
"rating": 5,
"content": "Narrator, tyler, marla: the unholy trinity",
"created": "2020-01-27T17:19:49.614Z"
},
{
"rating": 4,
"content": "Okay yeah I still think this is overrated. Still love u tho Fincher",
"created": "2020-01-27T17:19:27.442Z"
},
{
"rating": 5,
"content": "This was not at ALL what I expected.",
"created": "2020-01-27T17:19:00.217Z"
},
{
"rating": 5,
"content": "Not allowed to talk about this one thems the rules",
"created": "2020-01-27T17:18:28.748Z"
},
{
"rating": 5,
"content": "The other day I told my friend that Fight Club is my favorite movie. She replied \"I hate Fight Club. I hate boxing movies.\" I don't think that she's actually seen Fight Club.",
"created": "2020-01-27T17:17:42.854Z"
},
{
"rating": 5,
"content": "I look around, I look around, I see a lot of reviews for this classic. Which means a lot of people have been breaking the first two rules of Fight Club. Now if you are reading this then this warning is for you. Every word you read of this useless fine print is another second off your life. Don't you have other things to do? Is your life so empty that you honestly can't think of a better way to spend these moments? Or are you so impressed with authority that you give respect & credence to all that claim it? Do you read everything you are supposed to read? Do you think everything you are supposed to think? Buy what you are told you should want? Get out of your apartment. Meet a member of the opposite sex. Stop the excessive shopping & masturbation. Quit your job. Start a fight. Prove you're alive. If you don't claim your humanity, you will become a statistic. You have been warned.",
"created": "2020-01-27T16:56:21.794Z"
}
],
"reviewsAggregations": {
"COUNT": 12
}
}
]
}
}
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.
- GraphQL request
- Response
query MovieReviewsWithCommentsLikes {
movies(where: { identifier: "550-fight-club" }) {
reviews(orderBy: { created: DESC }, first: 10, skip: 0) {
rating
content
comments {
content
}
likesAggregations {
COUNT
}
}
reviewsAggregations {
COUNT
}
}
}
{
"data": {
"movies": [
{
"reviews": [
{
"rating": 5,
"content": "There are movies you hate, there are movies you love, and there are movies that changed your life.",
"comments": [
{
"content": "Word!"
}
],
"likesAggregations": {
"COUNT": 3
}
},
{
"rating": 4,
"content": "RE-TEACH MEN WHAT SATIRE IS",
"comments": [],
"likesAggregations": {
"COUNT": 1
}
},
{
"rating": 5,
"content": "brad pitt. omg brad pitt.",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "Ikea boy",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "Narrator, tyler, marla: the unholy trinity",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 4,
"content": "Okay yeah I still think this is overrated. Still love u tho Fincher",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "This was not at ALL what I expected.",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "Not allowed to talk about this one thems the rules",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "The other day I told my friend that Fight Club is my favorite movie. She replied \"I hate Fight Club. I hate boxing movies.\" I don't think that she's actually seen Fight Club.",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
},
{
"rating": 5,
"content": "I look around, I look around, I see a lot of reviews for this classic. Which means a lot of people have been breaking the first two rules of Fight Club. Now if you are reading this then this warning is for you. Every word you read of this useless fine print is another second off your life. Don't you have other things to do? Is your life so empty that you honestly can't think of a better way to spend these moments? Or are you so impressed with authority that you give respect & credence to all that claim it? Do you read everything you are supposed to read? Do you think everything you are supposed to think? Buy what you are told you should want? Get out of your apartment. Meet a member of the opposite sex. Stop the excessive shopping & masturbation. Quit your job. Start a fight. Prove you're alive. If you don't claim your humanity, you will become a statistic. You have been warned.",
"comments": [],
"likesAggregations": {
"COUNT": 0
}
}
],
"reviewsAggregations": {
"COUNT": 12
}
}
]
}
}