【问题标题】:ApolloClient.query with fragment gives error on react-native带有片段的 ApolloClient.query 在 react-native 上给出错误
【发布时间】:2017-05-05 11:21:07
【问题描述】:

我尝试在我的 react native 应用程序中使用 apollo 客户端来手动获取一些带有片段的 graphql 数据:

const client = new ApolloClient({
  networkInterface,
});

const userInfo = gql `
  fragment UserInfo on User {
    id
    facebookId
    bio
    name {
      full
    }
  }
`;

export const fetchUser = facebookUserId =>
  client.query(gql `
  {
    user(id: "${facebookUserId}") {
      ...${userInfo}
    }
  }`);

但这给出了这个堆栈跟踪:

Cannot read property 'definitions' of undefined
TypeError: Cannot read property 'definitions' of undefined
    at Object.getFragmentDefinitions (http://localhost:8081/index.ios.bundle?        platform=ios&dev=true&minify=false:80327:28)
    at Object.createFragment (http://localhost:8081/index.ios.bundle?    platform=ios&dev=true&minify=false:84393:38)
    at ApolloClient.query (http://localhost:8081/index.ios.bundle?    platform=ios&dev=true&minify=false:84253:13)

我是否错误地使用了 client.query?

【问题讨论】:

    标签: react-native react-apollo


    【解决方案1】:

    您是否尝试在查询后添加片段?

    export const fetchUser = facebookUserId =>
      client.query(gql`query {
        user(id: "${facebookUserId}") {
          ... UserInfo
        }
      }
      ${userInfo}
    `);
    

    【讨论】:

    • 感谢您指出该错误。不幸的是,它没有解决问题。我得到相同的堆栈跟踪。此外,如果我用没有片段的非常简单的东西替换查询,它仍然不起作用。客户端似乎还有另一个问题。
    猜你喜欢
    • 2019-07-16
    • 2021-02-05
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 2022-08-21
    相关资源
    最近更新 更多