Last active
July 14, 2016 15:04
-
-
Save saikat/338d6183019539520c3d044ffc8be085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createFragmentFromPropTypes } 'react-apollo' | |
import React from 'react' | |
function Child(props) { | |
return ( | |
<div> | |
Name: {props.person.name} <br /> | |
Email: {props.person.email} <br /> | |
</div> | |
) | |
} | |
Child.propTypes = { | |
person: React.PropTypes.shape({ | |
name: React.PropTypes.string, | |
email: React.PropTypes.string | |
}) | |
} | |
function Parent(props) { | |
if (props.data.loading) | |
return <div>Loading...</div> | |
return ( | |
<div> | |
<Child props.data.person /> | |
</div> | |
) | |
} | |
const mapQueriesToProps = ({ ownProps }) => { | |
data: { | |
query: gql`query { | |
person { | |
id, | |
...personFragment | |
} | |
}`, | |
fragments: {personFragment: createFragmentFromPropTypes(Child.propTypes.person)} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment