Skip to content

Instantly share code, notes, and snippets.

@macrozone
Created June 14, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macrozone/fb9eb12ffa117b76b07896fbae2f7a3b to your computer and use it in GitHub Desktop.
Save macrozone/fb9eb12ffa117b76b07896fbae2f7a3b to your computer and use it in GitHub Desktop.
import { compose } from 'recompose'
import { connect } from 'react-redux'
import { withNavigationFocus } from 'react-navigation'
import { graphql } from 'react-apollo'
import { isFunction } from 'lodash'
import type { State } from '../../../redux/rootReducer'
export const defaultOptions = polling => ({
pollInterval: polling ? DEFAULT_POLL_INTERVAL : 0,
errorPolicy: 'ignore',
})
export default (query, { options = {}, ...otherConfig } = {}) =>
compose(
withNavigationFocus,
connect((state: State) => ({
inForeground: state.core.device.inForeground,
})),
graphql(query, {
...otherConfig,
options: props => {
const result = {
...defaultOptions(shouldPoll(props)),
...(isFunction(options) ? options(props) : options),
}
// console.log(result)
return result
},
}),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment