【问题标题】:Apollo GraphQL client query returns introspection result instead of dataApollo GraphQL 客户端查询返回自省结果而不是数据
【发布时间】:2020-02-15 05:21:02
【问题描述】:

我目前正在尝试使用 Apollo 作为 GraphQLNextJS 应用程序的 Squidex API 获取数据/em> 客户。 在localhostdev/production 模式下,一切正常。

Heroku 上部署应用程序后,相同的查询返回自省模式作为结果,而不是预期的数据。在一个真实的例子中,通过运行如下查询:

{
    queryPageContents(search: "Home") {
      ...PagesFragmentsPageId
      data {
        ...PagesFragmentsPage
        ...PagesFragmentsHome
      }
    }
  }

  ${Pages.fragments.pageId}
  ${Pages.fragments.page}
  ${Pages.fragments.home}
}

基本上我是在询问有关网页的各种数据,使用片段等。 我的预期数据应该如下——比如localhost:

但是我在 Heroku 上收到了这个,而不是上面那个:

因此,我的应用程序无法渲染,因为我的代码查找名为 queryPageContents 的 JSON 节点 - 如第一个屏幕截图所示 - 但它当前正在接收 __schema 作为查询结果。所以这会导致前端出现500 错误。

我搜索了一下,发现这个graphql-disable-introspection 必须安装在服务器端。我不知道它是否可以解决这个问题,但我不知道这是怎么发生的。

对此有何建议?

提前感谢大家。

【问题讨论】:

    标签: graphql next.js apollo-client


    【解决方案1】:

    Squidex 的 Sebastian Stehle 注意到,通过在数据加载检查后推迟页面数据初始化,问题得到解决。在这样的 NextJS 场景中:

    [...]
      const {loading, error, data} = useQuery(PAGE_QUERY.pages.home);
      // Instead here, pages it's being moved after error/loading checking as follows
    
      // Exception check
      if (error) {
        return <ErrorDb error={error} />
      }
      // DB fetching check
      if (loading) {
        return null;
      }
    
      // Data initialization here
      const pages = data.queryPageContents;
    
      return (
       // Page
       [...]
      );
    [...]
    

    【讨论】:

      猜你喜欢
      • 2020-06-14
      • 2020-11-02
      • 2019-01-04
      • 2020-01-13
      • 2019-04-02
      • 2016-08-31
      • 2020-10-24
      • 2021-12-01
      • 2020-03-31
      相关资源
      最近更新 更多