Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* Initialize Apollo Client for GraphQL */
// You might want to set these manually if you're running your server somewhere else
const httpUri = Meteor.absoluteUrl('graphql'); // http://localhost:3000/graphql
const wsUri = Meteor.absoluteUrl('subscriptions').replace(/^http/, 'ws'); // ws://localhost:3000/subscriptions
// Apollo 2.0 now uses the extensible "ApolloLink" (the following does not rely on Meteor)
const link = ApolloLink.split(
operation => {
const operationAST = getOperationAST(operation.query, operation.operationName);
return !!operationAST && operationAST.operation === 'subscription';
},
new WebSocketLink({
uri: wsUri,
options: {
reconnect: true, // tells client to reconnect websocket after being disconnected (which will happen after a hot-reload)
// // might be helpful if you want to carry login state from client
// // it is recommended you use the secure version of websockets (wss) when transporting sensitive login information
// connectionParams: {
// authToken: localStorage.getItem("Meteor.loginToken")
// }
}
}),
new HttpLink({ uri: httpUri })
);
const cache = new InMemoryCache(window.__APOLLO_STATE);
const client = new ApolloClient({
});
const hasSubscriptionOperation = operation =>
operation.query.definitions.reduce(
(result, definition) => result || definition.operation === 'subscription',
false
);
// http://localhost:8080 is put behind a proxy by webpack (cors)
const uri = '/graphql';
const link = ApolloLink.from([
errorLink,
authLink.split(
hasSubscriptionOperation,
new WsLink({
uri: 'ws://localhost:8081/graphql',
options: { reconnect: true },
}),
new HttpLink({ uri })
),
]);
const cache = new Cache();
const client = new ApolloClient({
link,
cache: cache.restore(window.__APOLLO_STATE__ || {}),
});
export default () => (