I am using GatsBy GraphiQL to write a query to return a single element, but the query returns all of the elements. Here is my testing data:
{
"data": {
"mKT": {
"data": [
{
"name": "Apple",
"description": "apple's desc"
},
{
"name": "Orange",
"description": "orange's desc"
},
{
"name": "Banana",
"description": "banana's desc"
}
]
}
},
"extensions": {}
}
And, here is the GraphQL query:
query MyQuery {
mKT(data: {elemMatch: {name: {eq: "Apple"}}}) {
data {
name
description
}
}
}
I expect to get:
{
"name": "Apple",
"description": "apple's desc"
}
However, running the query returns all of the data. Any idea how to fix this issue?
Simply use:
The
filter
keyword should do the trick.Check the GraphQL Reference (in Gatsby docs) for further details.