I'm running a graphql query on contentful data, like so:
query test {
allContentfulCategory(limit: 1000) {
totalCount
edges {
node {
categoryName
contentful_id
event {
id
}
}
}
}
}
but instead of
event {
id
}
which returns an array of id's
I would like something like this:
event {
totalCount
}
to just get the length (i.e. amount of event's) and not an actual array of data.
Is there a way to do this?
Could I implement this as a custom gatsbyjs-transform-plugin of some kind? Any pointers on that?
Since you are already querying event id you can get the length of each node.
{data.allContentfulCategory.edges.map(({ node }) => {
return (
<div>
<p>{node.categoryName}</p>
<p>{node.event.length}</p>
</div>
)
})}
Sorry if my initial post wasn't clear, I would like to be able to do it the graphql query or somewhere other than the js layer, since I don't need the id's in the client, I just need the length only - seems like it's not an easy thing to do in graphql.
Okay, reformulating the question? Is it possible to write a gatsby plugin (maybe a transformer) that can be run on any [array] graphql results?
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!
Hey again!
It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
Thanks again for being part of the Gatsby community!
@supermoos have you found a way to do this?
Most helpful comment
@supermoos have you found a way to do this?