尝试使用 id 所在的 graphql 进行查询
Attempting to query with graphql where id is
我需要在 strapi/gatsby 中使用 graphql 获取查询,其中 id 是 {id}。
根据文档found here,您可以这样查询:
{
allStrapiArticle {
edges {
node {
id
title
content
}
}
}
}
这行得通,我可以查询,但是我只想获得一篇 ID 为 {id} 的文章;
我试过:
{
allStrapiArticle(id: "4") {
edges {
node {
id
title
content
}
}
}
}
还有:
{
allStrapiArticle {
edges {
node(id: "4") {
id
title
content
}
}
}
}
以上两个都给我一个错误。知道如何实现吗?
使用:
{
allStrapiArticle(filter: {id: {eq: "4" }}) {
edges {
node {
id
title
content
}
}
}
}
elemMatch
过滤器也可能对您的用例有用。
检查 localhost:8000/___graphql
游乐场以测试您的查询和过滤器。
更多参考资料:
我需要在 strapi/gatsby 中使用 graphql 获取查询,其中 id 是 {id}。 根据文档found here,您可以这样查询:
{
allStrapiArticle {
edges {
node {
id
title
content
}
}
}
}
这行得通,我可以查询,但是我只想获得一篇 ID 为 {id} 的文章;
我试过:
{
allStrapiArticle(id: "4") {
edges {
node {
id
title
content
}
}
}
}
还有:
{
allStrapiArticle {
edges {
node(id: "4") {
id
title
content
}
}
}
}
以上两个都给我一个错误。知道如何实现吗?
使用:
{
allStrapiArticle(filter: {id: {eq: "4" }}) {
edges {
node {
id
title
content
}
}
}
}
elemMatch
过滤器也可能对您的用例有用。
检查 localhost:8000/___graphql
游乐场以测试您的查询和过滤器。
更多参考资料: