GraphQL query examples
query GetUser($userId: ID!) {
user(id: $userId) {
id
name
email
profile {
avatar
bio
}
}
}
# Variables:
# {
# "userId": "123"
# }
query GetPosts($limit: Int!, $offset: Int!) {
posts(limit: $limit, offset: $offset) {
id
title
content
author {
id
name
}
comments {
id
text
author {
name
}
}
}
}
# Variables:
# {
# "limit": 10,
# "offset": 0
# }
fragment UserFields on User {
id
name
email
profile {
avatar
bio
}
}
fragment PostFields on Post {
id
title
content
createdAt
author {
...UserFields
}
}
query GetUserWithPosts($userId: ID!, $postLimit: Int!) {
user(id: $userId) {
...UserFields
posts(limit: $postLimit) {
...PostFields
comments {
id
text
author {
...UserFields
}
}
}
}
}
# Variables:
# {
# "userId": "123",
# "postLimit": 5
# }