Skip to content

Instantly share code, notes, and snippets.

View lmcgartland's full-sized avatar
💻
hacking away

Lucas McGartland lmcgartland

💻
hacking away
View GitHub Profile
// Create customFetch function for handling re-authorization
// This customFetch (or any fetch you pass to the link) gets uri and options as arguments. We'll use those when we actually execute a fetch.
const customFetch = (uri, options) => {
// In our application, the refresh token is stored in a redux store
// We create an instance of the state here so we can get the refresh token later in our request
let state = store.getState()
// This reference to the refreshingPromise will let us check later on if we are executing getting the refresh token.
this.refreshingPromise = null;
// Authentication Link Example from https://www.apollographql.com/docs/react/recipes/authentication.html#Header
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { setContext } from 'apollo-link-context';
import { InMemoryCache } from 'apollo-cache-inmemory';
const httpLink = createHttpLink({
uri: '/graphql',
});
import React from 'react';
import { ApolloProvider } from 'react-apollo';
import { Provider } from 'react-redux';
import hoistNonReactStatic from 'hoist-non-react-statics';
export default apolloAndReduxProviderHOC = (WrappedComponent, store, client) => {
class Enhance extends React.Component {
render () {
return (
<Provider store={store}>