Skip to content

Commit 25b8d01

Browse files
author
Carlos Rufo Jimenez
committed
2.3-end-queries-v2.1
1 parent 247caa3 commit 25b8d01

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

src/components/App.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
import React, { Component } from 'react';
2-
import logo from '../logo.svg';
3-
import '../styles/App.css';
1+
import React from 'react'
2+
import LinkList from './LinkList'
43

5-
class App extends Component {
6-
render() {
7-
return (
8-
<div className="App">
9-
<header className="App-header">
10-
<img src={logo} className="App-logo" alt="logo" />
11-
<h1 className="App-title">Welcome to React</h1>
12-
</header>
13-
<p className="App-intro">
14-
To get started, edit <code>src/App.js</code> and save to reload.
15-
</p>
16-
</div>
17-
);
18-
}
19-
}
20-
21-
export default App;
4+
export default () => <LinkList />

src/components/Link.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
3+
export default ({ link }) => (
4+
<div>
5+
{link.description} ({link.url})
6+
</div>
7+
)

src/components/LinkList.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react'
2+
import Link from './Link'
3+
import { Query } from 'react-apollo'
4+
import gql from 'graphql-tag'
5+
6+
const FEED_QUERY = gql`
7+
{
8+
feed {
9+
links {
10+
id
11+
createdAt
12+
url
13+
description
14+
}
15+
}
16+
}
17+
`
18+
19+
export default () => {
20+
const linksToRender = [
21+
{
22+
id: '1',
23+
description: 'Prisma turns your database into a GraphQL API 😎',
24+
url: 'https://www.prismagraphql.com'
25+
},
26+
{
27+
id: '2',
28+
description: 'The best GraphQL client',
29+
url: 'https://www.apollographql.com/docs/react/'
30+
}
31+
]
32+
33+
return (
34+
<Query query={FEED_QUERY}>
35+
{({ loading, error, data }) => {
36+
if (loading) return <div>Fetching</div>
37+
if (error) return <div>Error</div>
38+
39+
const linksToRender = data.feed.links
40+
41+
return (
42+
<div>
43+
{linksToRender.map(link => <Link key={link.id} link={link} />)}
44+
</div>
45+
)
46+
}}
47+
</Query>
48+
)
49+
}

0 commit comments

Comments
 (0)