小编Dar*_*iya的帖子

为什么在 api 工作正常的情况下,在fragment上使用apollo客户端查询会得到一个空对象?

我想获取动态类型的数据。为此,我在 graphql 查询中使用片段。Api 在 graphql Playground 中工作正常,但是当我尝试将它与 React-apollo 客户端集成时,它也给了我一个空对象以及警告!控制台中正在进行的启发式片段匹配。

当我使用 npm install 和 npm run start 时它也可以工作,但是当我切换到yarn install 和yarn run start 时它给了我一个错误。

我使用 IntrospectionFragmentMatcher 并将 fetchPolicy 设置为“缓存和策略”。

我还共享了用于客户端配置的 IntrospectionFragmentMatcher 的代码。

query GetContentSections($contentPageId: Int) {
  contentSection {
    searchContentSections(contentPageId: $contentPageId, status: [ACTIVE]) {
      id
      contentLayoutId
      sort
      sectionContainers {
        id
        sort
        snippets {
          id
          sort
          type: __typename
          ...quote
          ...text
          ...image
          ...video
          ...audio
          ...button
          ...popup
          ...map
          ...code
          ...app
        }
      }
    }
  }
}
fragment text on ContentSnippetTextType{
  text
}
fragment image on ContentSnippetImageType{
  assetId …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs graphql react-apollo apollo-client

7
推荐指数
1
解决办法
2254
查看次数