Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Last active June 1, 2019 16:42
Show Gist options
  • Save kianaditya/bf60a05fa9675939e63af40351d9ce9e to your computer and use it in GitHub Desktop.
Save kianaditya/bf60a05fa9675939e63af40351d9ce9e to your computer and use it in GitHub Desktop.
GitHub Graphql api demo
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