我尝试在我的本机应用程序中使用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?
答案 0 :(得分:0)
您是否尝试在查询后添加片段?
export const fetchUser = facebookUserId =>
client.query(gql`query {
user(id: "${facebookUserId}") {
... UserInfo
}
}
${userInfo}
`);