GraphQL Query: Filtering Edges Based on Node ID Matching Article ID

GraphQL Query: Filtering Edges Based on Node ID Matching Article ID


0

I have a GraphQL query that retrieves articles along with their related stores and associated price data. However, I want to filter the edges in the articlesConnection field to only include edges where the node.id matches the id of the article. Here’s the query I have:

query GetAllArticles($options: ArticleOptions) {
  articles(options: $options) {
    id
    name
    
    stores {
      articlesConnection {
        edges {
          current_price
          
          node {
            id
          }
        }
      }
    }
  }
}

And here’s a sample response I’m receiving:

{
  "id": "article1333", // match this
  "name": "Brašno Heebiesskus 440g",
  "stores": [
    {
      "articlesConnection": {
        "edges": [
          {
            "current_price": 1500,
            "node": {
              "id": "article123"
            }
          },
          { // with this
            "current_price": 1600,
            "node": {
              "id": "article1333"
            }
          }
        ]
      }
    }
  ]
}

Is there a way to modify the GraphQL query so that I only receive edges where the node.id matches the id of the article? For example, in the sample response above, I would like to include the edge with the current_price of 1600 because its node.id matches the id at the top of the response ("id": "article1333"). But I would like to exclude the edge with the current_price of 1500 because its node.id ("id": "article123") does not match the article’s id.

Output expectation, in short:

{
  "id": "article1333", 
  "name": "Brašno Heebiesskus 440g",
  "stores": [
    {
      "articlesConnection": {
        "edges": [
          { 
            "current_price": 1600,
            "node": {
              "id": "article1333"
            }
          }
        ]
      }
    }
  ]
}

Thanks

Share
Improve this question


Load 7 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *