Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
uri: config.webSocketEndpoint,
});
// Combine the links in a way that splits based on the operation
const link = split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
webSocketLink,
httpLink,
);
// Create a client with the combined links
return new ApolloClient({
cache: new InMemoryCache(),
link,
});
}
export function create({ initialState }: InitApollo): ApolloClient {
if (process.browser) {
persist();
}
return new ApolloClient({
connectToDevTools: process.browser, // comes from webpack
cache: cache().restore(initialState || {}),
ssrMode: !process.browser,
link: new HttpLink({ uri: API }) as ApolloLink, // TODO: types are wrong in graphql
queryDeduplication: true
});
}
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all'
},
query: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all'
}
// mutate: {
// errorPolicy: 'all'
// }
};
// const cache = new InMemoryCache({ dataIdFromObject: o => o.id });
const cache = new InMemoryCache();
const client = new ApolloClient({
link,
cache,
connectToDevTools: isDev,
defaultOptions
});
await persistCache({
cache,
storage: AsyncStorage,
debug: isDev
});
return client;
}
links.push(errorLink);
}
if (process.env.CLEANING_SCRIPTS_URI) {
links.push(
new RestLink({
uri: process.env.CLEANING_SCRIPTS_URI + "/",
headers: {
"Content-Type": "application/json"
}
})
);
}
links.push(coreLink);
// Client
export const client = new ApolloClient({
cache: new InMemoryCache(),
connectToDevTools: true,
link: ApolloLink.from(links)
});
ReactDOM.render(
,
document.getElementById("application-wrapper") ||
document.createElement("div")
);
* @flow
*/
import React, { Component } from 'react';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-client-preset';
import AppContainer from './src/AppContainer';
import ListPage from './src/components/ListPage';
const simpleApi = 'https://api.graph.cool/simple/v1/cjrh62bkka7l501132k2sp85b';
const httpLink = new HttpLink({ uri: simpleApi });
const client = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
});
export default class App extends Component {
render() {
return (
);
}
}
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import registerServiceWorker from './registerServiceWorker'
import { ApolloProvider } from 'react-apollo'
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-client-preset'
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
const client = new ApolloClient({
link: httpLink,
cache: new InMemoryCache()
})
ReactDOM.render(
,
document.getElementById('root')
)
registerServiceWorker()
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,
cache: new InMemoryCache(),
});
export default client;