Skip to content

Instantly share code, notes, and snippets.

@saikat
Last active July 14, 2016 15:04
Show Gist options
  • Save saikat/338d6183019539520c3d044ffc8be085 to your computer and use it in GitHub Desktop.
Save saikat/338d6183019539520c3d044ffc8be085 to your computer and use it in GitHub Desktop.
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