Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createClient(headers, token, initialState) {
let accessToken = token;
(async () => {
// eslint-disable-next-line no-param-reassign
accessToken = token || (await persist.willGetAccessToken());
})();
const authLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
authorization: accessToken
}
});
return forward(operation);
}).concat(httpLink);
return new ApolloClient({
headers,
link: authLink,
connectToDevTools: process.browser,
ssrMode: !process.browser,
cache: new InMemoryCache().restore(initialState || {})
});
}
import { InMemoryCache } from 'apollo-cache-inmemory'
import 'tachyons'
import './index.css'
import { split } from 'apollo-link'
import { WebSocketLink } from 'apollo-link-ws'
import { getMainDefinition } from 'apollo-utilities'
import App from './components/nav/layout/App'
const wsLink = new WebSocketLink({
uri: 'ws://localhost:4000/',
options: {
reconnect: true
}
})
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
const middlewareAuthLink = new ApolloLink((operation, forward) => {
const token = localStorage.getItem(AUTH_TOKEN)
const authorizationHeader = token ? `Bearer ${token}` : null
operation.setContext({
headers: {
authorization: authorizationHeader,
},
})
return forward(operation)
})
const httpLinkWithAuthToken = middlewareAuthLink.concat(httpLink)
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query)
return kind === 'OperationDefinition' && operation === 'subscription'
import {
ApolloClient,
ApolloLink,
InMemoryCache,
HttpLink,
} from 'apollo-client-preset';
const httpLink = new HttpLink({
uri: process.env.REACT_APP_GRAPHCOOL_SIMPLE_API,
});
const middlewareLink = new ApolloLink((operation, forward) => {
const token = localStorage.getItem('graphcoolToken');
const authorizationHeader = token ? `Bearer ${token}` : null;
operation.setContext({
headers: {
authorization: authorizationHeader,
},
});
return forward(operation);
});
const httpLinkWithAuthToken = middlewareLink.concat(httpLink);
const client = new ApolloClient({
link: httpLinkWithAuthToken,
import {
BrowserRouter as Router,
Route,
Switch,
} from 'react-router-dom'
import { ApolloProvider } from 'react-apollo'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloLink } from 'apollo-client-preset'
import { createUploadLink } from 'apollo-upload-client'
import UploadFile from './components/UploadFile'
import './index.css'
const authLink = new ApolloLink((operation, forward) => {
const token = JSON.parse(localStorage.getItem('AUTH_TOKEN'))
const authorizationHeader = token ? `Bearer ${token}` : null
operation.setContext({
headers: {
authorization: authorizationHeader
}
})
return forward(operation)
})
const client = new ApolloClient({
link: authLink.concat(createUploadLink({ uri: 'http://localhost:4000' })),
cache: new InMemoryCache()
})
ReactDOM.render(