- Try to run a query that returns the first ten stories and requests the following fields:
- ID, title, excerpt, publication date, who wrote the story, and the first ten comments for each story
query {
stories(first: 10) {
nodes {
id
title
excerpt
createdAt
writtenBy {
user {
name
}
}
comments(first: 10) {
nodes {
id
content
}
}
}
}
}
Can you extend the query to return the ten newest stories?
(add orderBy
)
query {
stories(orderBy: {field: createdAt, direction: desc}, first: 10) {
nodes {
id
title
excerpt
createdAt
writtenBy {
user {
name
}
}
comments(first: 10) {
nodes {
id
content
}
}
}
}
}
Member-Daten mit Fragment abfragen
- Create a fragment (
Author
) that selects aMember
's ID, as well as thename
andid
of the associated user- Use this fragment in both the stories and the comments to query member information
- In the stories, also query the member's
skills
fragment Author on Member {
id user { name id }
}
query {
stories(orderBy: {field: createdAt, direction: desc}, first: 10) {
nodes {
id
title
excerpt
createdAt
writtenBy {
...Author
skills
}
comments(first: 10) {
nodes {
id
content
writtenBy { ...Author }
}
}
}
}
}