Last active
December 5, 2016 19:34
-
-
Save stubailo/d7e0171d188c89c2c540a59a2e2a7871 to your computer and use it in GitHub Desktop.
graphql-anywhere proptypes
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 { propType } from 'graphql-anywhere'; | |
const CommentView = ({ comment }) => ( | |
<div> | |
<p>{ comment.content }</p> | |
<p>Posted by { comment.postedBy.login } on {comment.createdAt }</p> | |
</div> | |
); | |
CommentView.commentFragment = gql` | |
fragment CommentView on Comment { | |
id | |
postedBy { | |
login | |
} | |
createdAt | |
content | |
} | |
`; | |
CommentView.propTypes = { | |
// Works with both queries and fragments! | |
comment: propType(CommentView.commentFragment).isRequired, | |
}; | |
const goodData = { | |
id: 'asdf', postedBy: { login: 'sashko' }, | |
createdAt: '2016-12-05T19:32:21+00:00', content: 'I love GraphQL!', | |
}; | |
<CommentView comment={goodData} /> // OK | |
const badData = { | |
id: 'asdf', | |
createdAt: '2016-12-05T19:32:21+00:00', content: 'I love GraphQL!', | |
}; | |
<CommentView comment={badData} /> // PropType error! postedBy missing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment