ApolloClient readFragment returns 空对象
ApolloClient readFragment returns empty object
根据 the docs 这就是从 apollo 缓存中查询内容所需的全部内容,但它不起作用并且 console.log()
显示的是一个空对象。第一张图片显示我已缓存实体。
- 将
optimistic
更改为 false 不会更改结果
- 将 id 更改为“141”将 return 从空对象更改为 'null'
import gql from "graphql-tag";
"apollo-client": "^2.6.8",
"graphql-tag": "^2.10.0",
onClick: p => {
const readFragment = apolloClient.readFragment({
id: 141,
fragment: gql`
fragment myMarca on Marca {
id
}
`,
optimistic: true,
});
console.log(readFragment);
}
问题是我超过了 id: 141
。正确的做法是Marca:141
。在 Apollo Spectrum 社区内 this answer 找到它。
根据 the docs 这就是从 apollo 缓存中查询内容所需的全部内容,但它不起作用并且 console.log()
显示的是一个空对象。第一张图片显示我已缓存实体。
- 将
optimistic
更改为 false 不会更改结果 - 将 id 更改为“141”将 return 从空对象更改为 'null'
import gql from "graphql-tag";
"apollo-client": "^2.6.8",
"graphql-tag": "^2.10.0",
onClick: p => {
const readFragment = apolloClient.readFragment({
id: 141,
fragment: gql`
fragment myMarca on Marca {
id
}
`,
optimistic: true,
});
console.log(readFragment);
}
问题是我超过了 id: 141
。正确的做法是Marca:141
。在 Apollo Spectrum 社区内 this answer 找到它。