Pir*_*nha 5 react-apollo apollo-client
我开始使用graphQL和apollo。我正在做一些简单的查询和修改,但是当我尝试从apollo缓存访问数据时,我不断收到“找不到未定义对象的字段”,但是当使用apollo chrome插件时,它会返回正确的数据。
登录到我的应用程序后,我运行一个简单的查询,该查询从服务器获取用户对象。它记录正确,我可以在查询和缓存中看到我的用户数据在那里。
const ME_QUERY = gql`
query {
me {
_id
username
password
exchanges {
name
active
}
}
}
`;
<Query query={ME_QUERY}>
{({loading, error, data}) => {
if (error) {
return <Error error={error.message} />;
}
if (data) {
console.log(data, 'data');
}
return <div>asdf</div>
}}
</Query>
Run Code Online (Sandbox Code Playgroud)
我包装了withApollo,可以在要查询的组件中很好地记录客户端对象。我运行以下代码:
componentDidMount() {
console.log(this.props.client.readQuery, 'propps');
const user = this.props.client.readQuery({
query: gql`
{
me {
_id
username
password
exchanges {
name
active
}
}
}
`
});
console.log(user, 'user');
Run Code Online (Sandbox Code Playgroud)
并导致未捕获的错误:找不到对象未定义的字段我已经尝试过添加变量,但无济于事。
哪个对象未定义?知道为什么我的查询失败吗?
| 归档时间: |
|
| 查看次数: |
1506 次 |
| 最近记录: |