如何使用内容数据中的特定值筛选GraphQL查询内容。例如,由于下面的GraphQL查询,我收到了内容。
查询MyQuery { allPages {边缘{节点{ content }
从上面的查询中,我收到了如下内容。我正在尝试使用"Type“值(Veg/果树)筛选出结果。如何过滤出蔬菜的内容,以只显示水果的内容。
{“节点”:{“内容”:{“类型”:“水果”,“值”:{“文本”:“橙色”},{“类型”:“水果”,“值”:{“文本”:"Apple“},{”节点“:{”内容“:{”类型“:”类型“,”值“:{”文本“:”花椰菜“},{ "type":"Veg","value":{ "Text":"Lettuce“}
发布于 2021-01-12 07:27:26
query MyQuery(filter: { content: { type: { eq: "Fruit" } } }) {
allPages {
edges {
node {
content
}
}
}
}注意:根据您的问题,我假设type是content__中的一个属性。如果不适应你的需要,就让它适应。使用_localhost:8000/___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.vegetables中。
https://stackoverflow.com/questions/65679071
复制相似问题