Skip to content

Commit f863590

Browse files
author
Carlos Rufo Jimenez
committed
Merge branch '2.3-end-queries-v2.1' into 3.2-start-mutations-v2.1
2 parents c5e0199 + 25b8d01 commit f863590

File tree

4 files changed

+42
-50
lines changed

4 files changed

+42
-50
lines changed

server/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const server = new GraphQLServer({
2121
typeDefs: 'src/generated/prisma.graphql',
2222
endpoint: '__PRISMA_ENDPOINT__',
2323
secret: 'mysecret123',
24-
debug: true
25-
})
26-
})
24+
debug: true,
25+
}),
26+
}),
2727
})
2828

2929
server.start(() => console.log('Server is running on http://localhost:4000'))

src/components/App.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import LinkList from './LinkList'
33

4-
class App extends Component {
5-
render() {
6-
return <LinkList />
7-
}
8-
}
9-
10-
export default App
4+
export default () => <LinkList />

src/components/Link.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22

3-
class Link extends Component {
4-
render() {
5-
return (
6-
<div>
7-
<div>
8-
{this.props.link.description} ({this.props.link.url})
9-
</div>
10-
</div>
11-
)
12-
}
13-
14-
_voteForLink = async () => {
15-
// ... you'll implement this in chapter 6
16-
}
17-
}
18-
19-
export default Link
3+
export default ({ link }) => (
4+
<div>
5+
{link.description} ({link.url})
6+
</div>
7+
)

src/components/LinkList.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import Link from './Link'
33
import { Query } from 'react-apollo'
44
import gql from 'graphql-tag'
55

6-
// 1
76
const FEED_QUERY = gql`
8-
# 2
9-
query FeedQuery {
7+
{
108
feed {
119
links {
1210
id
@@ -16,24 +14,36 @@ const FEED_QUERY = gql`
1614
}
1715
}
1816
}
19-
`;
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
2040

21-
class LinkList extends Component {
22-
render() {
2341
return (
24-
<Query query={FEED_QUERY}>
25-
{(result) => {
26-
if (result.loading) return <div>Loading</div>;
27-
if (result.error) return <div>Error</div>;
28-
29-
const { data } = result;
30-
const linksToRender = data.feed.links;
31-
32-
return <div>{linksToRender.map(link => <Link key={link.id} link={link} />)}</div>;
33-
}}
34-
</Query>
42+
<div>
43+
{linksToRender.map(link => <Link key={link.id} link={link} />)}
44+
</div>
3545
)
36-
}
46+
}}
47+
</Query>
48+
)
3749
}
38-
39-
export default LinkList;

0 commit comments

Comments
 (0)