Graphql props.client.subscribe from with Apollo HOC的API文档
在哪里可以找到props.client.subscribe的para文档 如果我和阿波罗HOC一起使用Graphql props.client.subscribe from with Apollo HOC的API文档,graphql,react-apollo,Graphql,React Apollo,在哪里可以找到props.client.subscribe的para文档 如果我和阿波罗HOC一起使用 import React, {Component, PureComponent} from 'react'; import PropTypes from 'prop-types'; import {Subscription, Query} from 'react-apollo'; import gql fr
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)
}
import React,{Component,PureComponent}来自'React';
从“道具类型”导入道具类型;
从'react apollo'导入{订阅,查询};
从“graphql标签”导入gql;
从'react apollo'导入{withApollo};
导出默认函数newHeartbeatHOC(ChildComponent){
类OuterComponent扩展了PureComponent{
建造师(道具){
超级(道具)
此.state={
数据:{}
}
}
订阅=(gqlStr)=>{
this.props.client.subscribe({
//怎么做?
})
}
render(){
返回()
}
}
阿波罗返回(外部组件)
}
我在apollo文档中找不到它,但是client.subscribe需要1-3个参数。查询、变量(如果有)和fetchpolicy(如果有)
subscribe函数不返回承诺。如何获取返回结果?如果您记录它,它将返回什么?
this.props.client.subscribe({
query: YOUR_QUERY,
variables: {{ id: 1 }},
fetchPolicy: 'network-only'
})