【问题标题】:I am running a Gatsby Graphql queries successfully with GraphiQL, but on NextJS (GraphQL queries configured with Apollo) the same queries don't work?我正在使用 GraphiQL 成功运行 Gatsby Graphql 查询,但是在 NextJS(使用 Apollo 配置的 GraphQL 查询)上,相同的查询不起作用?
【发布时间】:2021-11-18 02:48:06
【问题描述】:
  • 确认一下,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 工作!

【问题讨论】:

标签: reactjs graphql next.js graphiql


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-05-25
    • 1970-01-01
    • 2020-05-13
    • 2020-06-09
    • 2017-02-25
    • 2020-11-12
    • 2016-11-30
    • 2018-10-07
    • 2018-05-04
    相关资源
    最近更新 更多