来自Apollo HOC的props.client.subscribe的API文档

时间:2018-09-05 14:54:21

标签: graphql react-apollo

在哪里可以找到props.client.subscribe的para文档

如果我与Apollo HOC一起使用?

import React, {Component, PureComponent}          from 'react';
import PropTypes                                  from 'prop-types';
import {Subscription, Query}   from 'react-apollo';
import gql from 'graphql-tag';
import { withApollo } from 'react-apollo';




export default function newHeartbeatHOC(ChildComponent) {
  class OuterComponent extends PureComponent {
    constructor(props) {
      super(props)
      this.state = {
        data: {}
      }
    }

    subscribe = (gqlStr) => {
      this.props.client.subscribe({
        // how? 
      })

    }

    render() {
      return (<ChildComponent data={this.state.data} />)
    }
  }
  return withApollo(OuterComponent)


}

1 个答案:

答案 0 :(得分:0)

我在apollo文档中找不到它,但是client.subscribe期望使用1-3个参数。查询,变量(如果有)和fetchpolicy(如果有)。

this.props.client.subscribe({
  query: YOUR_QUERY,
  variables: {{ id: 1 }},
  fetchPolicy: 'network-only'
})