当试图调用Apollo Client Query时,我总是得到loading:true,networkStatus:true

时间:2018-03-23 06:13:20

标签: reactjs react-apollo apollo-client

查询:

HOUSEDETAIL : gql`
query houseDetail($_id:ID){
 houseDetail(_id:$_id) {
   address
   address1
   street
   phoneNumber
   houseNo
 }
}
`,

尝试调用apolloClient时的React中的代码:

    const Page2 = compose(graphql(query.HOUSEDETAIL,{name:'houseDetail', options: (props) => ({variables: {_id:props.houseAddress._id,fetchPolicy: 'network-only'}})})) (Dashboard) 

错误在浏览器控制台中显示如下:

        props{"houseAddress":{},"houseDetail":{"variables":{"fetchPolicy":"network-only"},"loading":true,"networkStatus":1}}

1 个答案:

答案 0 :(得分:1)

这似乎是一个常见问题,通常可以通过添加notifyOnNetworkStatusChange: true

来解决

在您的特定情况下:

const Page2 = compose(
  graphql(
    query.HOUSEDETAIL,
    {
       name:'houseDetail', 
       options: (props) => ({
         variables: { 
           _id:props.houseAddress._id
         }, // ====> this bracket was also misplaced on your example code
         fetchPolicy: 'network-only',
         notifyOnNetworkStatusChange: true
       })
    }
  )
)(Dashboard) 

有关notifyOnNetworkStatusChange的更多信息可以在ReactApollo docs中找到: