Skip to content

Instantly share code, notes, and snippets.

@stubailo
Last active December 5, 2016 19:34
Show Gist options
  • Save stubailo/d7e0171d188c89c2c540a59a2e2a7871 to your computer and use it in GitHub Desktop.
Save stubailo/d7e0171d188c89c2c540a59a2e2a7871 to your computer and use it in GitHub Desktop.
graphql-anywhere proptypes
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