关于从阿波罗中的客户端缓存查询对象,我有一个简短的问题。
我有一个像这样的初始缓存状态:
cache.writeData({
data: { value1: true, value2: { test: "123" } }
});将查询数据附加到组件的容器:
import EditModalComponent from "..";
import gql from "graphql-tag";
import { graphql } from "@apollo/react-hoc";
import { compose, pure } from "recompose";
const QUERY2 = gql`
query data {
value2 @client {
test
}
}
`;
const query2 = graphql(QUERY2, {
name: "query2"
});
const EditModalWithData = compose(query2, pure)(EditModalComponent);
export default EditModalWithData;如果我尝试查询value1,一切正常,但是如果我尝试使用上面的查询查询value2,我只会收到一个没有任何值的查询响应。
这是我在组件道具中收到的响应:
variables: {}
refetch: ƒ (variables)
fetchMore: ƒ (fetchMoreOptions)
updateQuery: ƒ (mapFn)
startPolling: ƒ (pollInterval)
stopPolling: ƒ ()
subscribeToMore: ƒ (options)
loading: false
networkStatus: 7
error: undefined
called: true
XXXXXX <- here should be something like: test: "123"谢谢你的帮忙!
发布于 2020-03-09 10:51:27
我找到了解决办法。您需要在booth参数后面使用wirte @client:
const QUERY2 = gql`
query data {
value2 @client {
test @client
}
}
`;https://stackoverflow.com/questions/60562562
复制相似问题