1

我尝试在我的 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?

4

1 回答 1

0

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

export const fetchUser = facebookUserId =>
  client.query(gql`query {
    user(id: "${facebookUserId}") {
      ... UserInfo
    }
  }
  ${userInfo}
`);
于 2016-12-20T10:35:08.360 回答