如何使用内容中的特定值过滤GraphQL查询内容?

如何使用内容中的特定值过滤GraphQL查询内容?,graphql,gatsby,Graphql,Gatsby,如何使用内容数据中的特定值过滤GraphQL查询内容。例如,我收到的内容是以下GraphQL查询的结果 从上述查询中,我收到了如下内容。我试图使用“Type”值(Veg/Fruit)过滤掉结果。如何过滤蔬菜内容以仅显示水果内容 使用: 注意:根据您的问题,我假设type是content中的一个属性。如果没有,就根据你的需要调整它。使用localhost:8000/\uuuuuuu graphql可以帮助您在过滤器中创建正确的graphql查询 如果要为所拥有的每种类型的数据创建不同的查询,可以将

如何使用内容数据中的特定值过滤GraphQL查询内容。例如,我收到的内容是以下GraphQL查询的结果

从上述查询中,我收到了如下内容。我试图使用“Type”值(Veg/Fruit)过滤掉结果。如何过滤蔬菜内容以仅显示水果内容

使用:

注意:根据您的问题,我假设
type
content
中的一个属性。如果没有,就根据你的需要调整它。使用
localhost:8000/\uuuuuuu graphql
可以帮助您在过滤器中创建正确的graphql查询

如果要为所拥有的每种类型的数据创建不同的查询,可以将其别名为:

query MyQuery {
  fruit: allPages (filter: { content: { type: { eq: "Fruit" } } }) {
    edges {
      node {
        content
      }
    }
  }
  vegetables: allPages (filter: { content: { type: { eq: "Veg" } } }) {
    edges {
      node {
        content
      }
    }
  }
}

在本例中,您的数据将位于
props.data.fruit
props.data.vegets

中,我将测试此方法并将状态发布在此处。。谢谢@Ferran
{
  "node": {
    "content": [
      {
        "type": "Fruit",
        "value": {
          "Text": "Orange"
        }
      },
      {
        "type": "Fruit",
        "value": {
          "Text": "Apple"
        }
      }
    ]
  }
},
{
  "node": {
    "content": [
      { 
        "type": "Veg",
        "value": {
          "Text": "Broccoli"
        }
      },
      {
        "type": "Veg",
        "value": {
          "Text": "Lettuce"
        }
      }
    ]
  }
}
query MyQuery(filter: { content: { type: { eq: "Fruit" } } }) {
  allPages {
    edges {
      node {
        content
      }
    }
  }
}
query MyQuery {
  fruit: allPages (filter: { content: { type: { eq: "Fruit" } } }) {
    edges {
      node {
        content
      }
    }
  }
  vegetables: allPages (filter: { content: { type: { eq: "Veg" } } }) {
    edges {
      node {
        content
      }
    }
  }
}