File tree Expand file tree Collapse file tree 4 files changed +61
-1
lines changed Expand file tree Collapse file tree 4 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
2
import logo from '../logo.svg'
3
+ import StarCount from './StarCount'
3
4
4
5
class App extends Component {
5
6
render ( ) {
6
7
return (
7
8
< div className = "App" >
8
9
< header className = "App-header" >
10
+ < StarCount />
9
11
< img src = { logo } className = "App-logo" alt = "logo" />
10
12
< h1 className = "App-title" > The GraphQL Guide</ h1 >
11
13
</ header >
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change @@ -3,8 +3,25 @@ import ReactDOM from 'react-dom'
3
3
import './index.css'
4
4
import App from './components/App'
5
5
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'
6
10
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
+ )
8
25
9
26
registerServiceWorker ( )
10
27
You can’t perform that action at this time.
0 commit comments