How to use the apollo-boost.ApolloLink.split function in apollo-boost

To help you get started, we’ve selected a few apollo-boost 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 mgm-interns / team-radio / client / src / Config / Apollo.ts View on Github external
connectionParams: {
        token: localStorage.getItem('token') || undefined,
        refreshToken: localStorage.getItem('refreshToken') || undefined,
        clientId: localStorage.getItem('clientId') || undefined
      },
      connectionCallback: () => {
        if (connectionAttempts > 0) {
          console.log('Reconnect successful! Start resetting apollo store');
          if (client) client.resetStore();
        }
        connectionAttempts += 1;
      }
    }
  });

  const link = ApolloLink.split(
    ({ query }) => {
      const definition = getMainDefinition(query);
      return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
    },
    wsLink,
    httpLink
  );

  const errorLink = ErrorLink.onError(error => {
    console.error(error);
    if (!config.onError) return;
    if (error.networkError) {
      const { message } = error.networkError;
      if (/Failed to fetch/.test(message)) {
        config.onError(message, 'failed_to_fetch');
      }
github penta-jelly / re-radio / client / src / lib / apollo / init.ts View on Github external
}));

    return next ? next(operation) : null;
  });
  const httpLink = ApolloLink.from([authLink, batchLink]);

  const subscriptionClient = new SubscriptionClient(`${isSecureProtocol() ? 'wss' : 'ws'}://${host}/graphql`, {
    reconnect: true,
    connectionParams: () => {
      const token = localStorage.getItem('token');
      return { Authorization: token };
    },
  });
  const wsLink = new WebSocketLink(subscriptionClient);

  const link = ApolloLink.split(
    ({ query }) => {
      const definition = getMainDefinition(query);
      return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
    },
    wsLink,
    httpLink,
  );

  (window as any).subscription = subscriptionClient;
  return {
    healthEndpoint,
    apollo: new ApolloClient({ link, cache: new InMemoryCache() }),
    subscription: subscriptionClient,
  };
}