Skip to content

Commit b3ed68d

Browse files
committed
Add <StarCount />
1 parent 94266e1 commit b3ed68d

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { Component } from 'react'
22
import logo from '../logo.svg'
3+
import StarCount from './StarCount'
34

45
class App extends Component {
56
render() {
67
return (
78
<div className="App">
89
<header className="App-header">
10+
<StarCount />
911
<img src={logo} className="App-logo" alt="logo" />
1012
<h1 className="App-title">The GraphQL Guide</h1>
1113
</header>

src/components/StarCount.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Query } from 'react-apollo'
4+
import gql from 'graphql-tag'
5+
6+
const StarCount = ({ githubStars, loading }) => {
7+
return (
8+
<a className="StarCount" href="https://github.com/GraphQLGuide/guide">
9+
{githubStars}
10+
</a>
11+
)
12+
}
13+
14+
StarCount.propTypes = {
15+
githubStars: PropTypes.number,
16+
loading: PropTypes.bool.isRequired
17+
}
18+
19+
const STARS_QUERY = gql`
20+
query StarsQuery {
21+
githubStars
22+
}
23+
`
24+
25+
export default () => (
26+
<Query query={STARS_QUERY}>
27+
{({ data: { githubStars }, loading }) => (
28+
<StarCount githubStars={githubStars} loading={loading} />
29+
)}
30+
</Query>
31+
)

src/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,25 @@ import ReactDOM from 'react-dom'
33
import './index.css'
44
import App from './components/App'
55
import registerServiceWorker from './registerServiceWorker'
6+
import { ApolloClient } from 'apollo-client'
7+
import { ApolloProvider } from 'react-apollo'
8+
import { InMemoryCache } from 'apollo-cache-inmemory'
9+
import { createHttpLink } from 'apollo-link-http'
610

7-
ReactDOM.render(<App />, document.getElementById('root'))
11+
const link = createHttpLink({
12+
uri: 'https://api.graphql.guide/graphql'
13+
})
14+
15+
const cache = new InMemoryCache()
16+
17+
const client = new ApolloClient({ link, cache })
18+
19+
ReactDOM.render(
20+
<ApolloProvider client={client}>
21+
<App />
22+
</ApolloProvider>,
23+
document.getElementById('root')
24+
)
825

926
registerServiceWorker()
1027

0 commit comments

Comments
 (0)