Take for example the following component:
ProfileWithData.js
import React, { Component, PropTypes } from 'react'; import { graphql } from 'react-apollo'; import gql from 'graphql-tag'; class Profile extends Component { ... } Profile.propTypes = { data: PropTypes.shape({ loading: PropTypes.bool.isRequired, currentUser: PropTypes.object, }).isRequired, };
It would be easy to wrap its component of a higher order :
Profile.js
import React, { Component, PropTypes } from 'react'; export class Profile extends Component { ... } Profile.propTypes = { data: PropTypes.shape({ loading: PropTypes.bool.isRequired, currentUser: PropTypes.object, }).isRequired, };
createProfileWithData.js
import React, { Component, PropTypes } from 'react'; import { graphql } from 'react-apollo'; import { Profile } from './Profile' export default function createProfileWithData(query) => { return graphql(query)(Profile); }
Then you will use it as follows:
Page.js
import React, { Component, PropTypes } from 'react'; import gql from 'graphql-tag'; import createProfileWithData from './createProfileWithData'; class Page extends Component { renderProfileWithData() { const { textQuery } = this.props;
I think you get the point.
Of course, your profile did not receive props.data.currentUser , rather, it will be props.data.* Depending on the root queries, and you will process it accordingly depending on the content.
Note : this was written directly in Stack Overflow, so if you have any problems - lmk, and I will fix it.