Skip to content

How to get only elements with related values in GraphQL #1381

Answered by yorek
yorek asked this question in Q&A
Discussion options

You must be logged in to vote

You can get what you want by using also filter parameter, using the nested object also to filter out unwanted results. In this specific case the GraphQL query would be:

query Test {
  categories(filter: {subcategories: {id: {isNull: false}}}) {
    items {
      id
      category      
    }
  }
}

The Category and Subcategory entities have both a relationship defined in the configuration file, so that such filtering is possible. Here's the entity section of the configuration file:

"entities": {
  "Category": {
    "source": "dbo.category",
    "permissions": [{
        "role": "anonymous",
        "actions": [ "*" ]
      }],
    "relationships": {
      "subcategories": {
        "cardin…

Replies: 1 comment

Comment options

yorek
Mar 29, 2023
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by Aniruddh25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant