Skip to content

Commit 1669eac

Browse files
committed
Integrated the apollo client with the graphql schema and apis
1 parent c28032d commit 1669eac

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/App.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom';
33
import './scss/main.scss'
4+
import { ApolloProvider } from '@apollo/react-hooks'
5+
import ShowCountries from '../src/components/ShowCountries'
6+
import ApolloClient from 'apollo-boost'
7+
8+
const client = new ApolloClient({
9+
uri: 'https://countries-274616.ew.r.appspot.com/'
10+
})
11+
412
const App = () => {
513
return (
6-
<div>asd</div>
14+
<ApolloProvider client={client}>
15+
<div className="">
16+
<ShowCountries/>
17+
</div>
18+
</ApolloProvider>
719
)
820
}
921

src/components/ShowCountries.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { useQuery } from '@apollo/react-hooks';
3+
import { gql } from 'apollo-boost';
4+
5+
const GET_COUNTRIES = gql `
6+
query {
7+
Country {
8+
name
9+
area
10+
nativeName
11+
}
12+
}
13+
`
14+
15+
16+
const showCountries = () => {
17+
const { loading, error, data } = useQuery(GET_COUNTRIES);
18+
19+
return(
20+
<div>
21+
{ !loading &&
22+
data.Country.map((country , i) =>{
23+
return(
24+
<li key={i}>{country.name} ---- {country.nativeName} --- {country.area}</li>
25+
)
26+
})
27+
}
28+
</div>
29+
)
30+
}
31+
32+
export default showCountries;

0 commit comments

Comments
 (0)