Last active
May 24, 2018 19:10
-
-
Save gregberge/45235aabdba7beac31af594a787d32a2 to your computer and use it in GitHub Desktop.
FraQL preview π
This file contains hidden or 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 React from 'react' | |
import gql from 'fraql' | |
const ArticleCard = ({ article }) => ( | |
<div> | |
<h1>{article.title}</h1> | |
<p>{article.description}</p> | |
</div> | |
) | |
ArticleCard.fragments = { | |
article: gql` | |
fragment _ on Article { | |
title | |
description | |
} | |
` | |
} | |
export default ArticleCard |
This file contains hidden or 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 React from 'react' | |
import { Query } from 'apollo-client' | |
import gql from 'graphql-tag' | |
import ArticleCard from './ArticleCard' | |
const ARTICLES = gql` | |
query Articles { | |
articles { | |
id | |
${ArticleCard.fragments.article} | |
} | |
} | |
` | |
const ArticleList = ({ articles }) => ( | |
<div> | |
<Query query={ARTICLES}> | |
{({ data }) => data.articles && data.articles.map(article => ( | |
<ArticleCard key={article.id} article={article} /> | |
))} | |
</Query> | |
</div> | |
) | |
export default ArticleList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment