react-apollo
提供轉換組件的道具來查詢變量的能力:react-apollo - 如何從包裝組件中設置查詢變量?
<MyComponentWithData propsForQueryVariables={...} />
但我需要從包裝組件變量開始查詢。
喜歡的東西:
class MyComponent extends React.Component {
//...
onReady() {
// should be first request to server
this.props.refetch({
// variables here
})
}
onFilterChanged() {
this.props.refetch({
// new variables here
})
}
}
const MyComponentWithData = graphql(QUERY, {
options: {
waitUntilComponentStartQuery: true
// pollInterval:...
},
props({ data: { items, refetch } }) {
return {
items: items,
refetch: refetch
};
}
})(MyComponent);
UPDATE
QUERY
爲MyComponent
看起來像
query getItems($filter: JSON!) {
items(filter: $filter) {
id
name
}
}
filter
是不能爲空。所以第一個請求應該有有效變量filter
,並且這個變量應該在包裝組件中創建。
使用graphcool我無法獲得過濾器的工作,說明一個不能傳遞對象作爲孩子等。任何想法從哪裏去? –