Why I need to do this: I'm using graphql + gatsby + contentful. I'm using the rich text field in Contentful which allows to embed object references inside of markdown. I'd like to display the embedded entry.
My query looks like this:
export const pageQuery = graphql`
query BlogPostBySlug($slug: String!) {
richTextField {
content {
nodeType
data {
target {
sys {
id
}
}
}
}
}
}
}
`
The richTextField.content comes back looking like this:
{
"data": {
"target": {
"sys": {
"id": "5wVh2a6XvySacEioOEMyqQ",
}
}
},
}
The id, "5wVh2a6XvySacEioOEMyqQ", is a reference to another database entry. I can see two potential ways in how this might work:
Some way of telling graphql that the id in the query refers to the other database model and have it autopopulate fields. Is this possible?
Get the results of this query, collect all the ids and construct another query where it searches for entries with those ids. It seems like apollo might be a solution, but it doesn't work well with gatsby. Is this possible?
What is the best way to do this?
Thank you! :)