Skip to content

Instantly share code, notes, and snippets.

@raphox
Created June 4, 2020 02:04
Show Gist options
  • Select an option

  • Save raphox/893f3bbf560e840f4e6356f144a99d2b to your computer and use it in GitHub Desktop.

Select an option

Save raphox/893f3bbf560e840f4e6356f144a99d2b to your computer and use it in GitHub Desktop.
// ...
// Create an http link:
const httpLink = new HttpLink({
uri: "http://localhost:4000/graphql",
});
// Create a WebSocket link:
const wsLink = new WebSocketLink({
uri: `ws://localhost:4000/graphql`,
options: {
reconnect: true,
},
});
// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
wsLink,
httpLink
);
const client = new ApolloClient({ link, cache: new InMemoryCache() });
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment