![](/img/trans.png)
[英]Next/React-Apollo: React props not hooked up to apollo cache when query comes from getInitialProps
[英]Apollo query object values from cache
我有一个关于从 apollo 中的客户端缓存查询对象的快速问题。
我有一个这样的初始缓存状态:
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"
谢谢你的帮助!
我找到了解决方案。 您需要在booth参数后面写入@client :
const QUERY2 = gql`
query data {
value2 @client {
test @client
}
}
`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.