Last active
June 1, 2019 16:42
-
-
Save kianaditya/bf60a05fa9675939e63af40351d9ce9e to your computer and use it in GitHub Desktop.
GitHub Graphql api demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import './App.css'; | |
import { ApolloClient } from "apollo-boost"; | |
import { ApolloProvider } from "react-apollo"; | |
import MyProfile from './components/MyProfile'; | |
import { setContext } from 'apollo-link-context' | |
import { HttpLink } from 'apollo-link-http' | |
import { InMemoryCache } from 'apollo-boost' | |
const httpLink = new HttpLink({ uri: 'https://api.github.com/graphql' }) | |
const authLink = setContext((_, { headers }) => { | |
return { | |
headers: { | |
...headers, | |
authorization: `Bearer ${ | |
process.env.REACT_APP_GITHUB_PERSONAL_ACCESS_TOKEN | |
}` | |
} | |
} | |
}) | |
const link = authLink.concat(httpLink) | |
const client = new ApolloClient({ | |
link: link, | |
cache: new InMemoryCache() | |
}) | |
const App = () => { | |
return ( | |
<ApolloProvider client={client}> | |
<div className="App"> | |
<h1>GitHub API</h1> | |
< MyProfile/> | |
</div> | |
</ApolloProvider> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment