How to use the apollo-link-ws function in apollo-link-ws

To help you get started, we’ve selected a few apollo-link-ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Pitchlyapp / meteor-apollo2 / client / main.js View on Github external
/* 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({
github okgrow / advanced-graphql / web / src / client.js View on Github external
});

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 () => (

apollo-link-ws

WebSocket transport layer for GraphQL

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Popular apollo-link-ws functions

Similar packages