0
  • 只是为了确认一下,NextJS 和 Gatsby 都连接到与 GraphQL 兼容的 Strapi api,并且我的服务器在 http://localhost:1337 上运行
  • 另外,我可以通过 http://localhost:1337/graphql 访问 GraphQL 游乐场

然而,Gatsby 让我能够通过 GraphiQL 在 http://localhost:8000/___graphiql 上运行 GraphQL,这就是我的差异开始的地方......

  • Gatsby 提供的 http://localhost:8000/ 上的 GraphiQL 非常棒。我更喜欢 GraphQL 操场,您将在 http://localhost:1337/graphql 的暗模式下在底部屏幕截图中看到它

这是我通过 GraphiQL 运行的关于 Gatsby 的成功 GraphQL 查询: 在此处输入图像描述

  • 我希望 GraphiQL 中的相同查询在 http://localhost:1337/graphql 上的 Strapi 后端服务器中工作
  • 确切地说,这是在 GraphiQL 上成功运行的 GraphQL 查询:
query MyQuery {
  allStrapiProduct(filter: {featured: {eq: true}}) {
    edges {
      node {
        name
        strapiId
        variants {
          price
          qty
          product
        }
      }
    }
  }
}

在这里,我尝试通过 http://localhost:1337/graphql 上的标准 GraphQL 操场通过我的 Strapi 后端服务器运行 GraphQL 查询,以便我可以将其包含在我的 NextJS 项目中: 在此处输入图像描述

请帮助获取这个 GraphiQL 查询以及我通过 Gatsby 运行的所有其他 GraphiQL 查询,以便通过 NextJS 工作!

4

1 回答 1

2

我相信您的两个 GraphQL 服务器正在服务于不同的模式。也就是说,虽然allStrapiProduct在 GraphiQL 中工作,但您需要product在strapi 中使用。同样,filter在 GraphiQL 中,但where在 Strapi 中。

不同的模式

于 2021-09-25T07:15:25.207 回答