@graphql-sse/apollo-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

@graphql-sse/apollo-client

A client for GraphQL subscription using Server Sent Events.

Installation

npm install @graphql-sse/apollo-client

Usage

Basic Example

The snippet below is from the Example React App where you have a full working example App.

import { split, HttpLink, ApolloClient, InMemoryCache } from '@apollo/client';
import { getMainDefinition } from '@apollo/client/utilities';
import { ServerSentEventsLink } from '@graphql-sse/apollo-client';

const httpLink = new HttpLink({
  uri: 'http://localhost:4000/graphql',
});

const sseLink = new ServerSentEventsLink({
  graphQlSubscriptionUrl: 'http://localhost:4000/graphql',
});

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

export const client = new ApolloClient({
  link: splitLink,
  cache: new InMemoryCache(),
});

Package Sidebar

Install

npm i @graphql-sse/apollo-client

Weekly Downloads

53

Version

0.0.19

License

MIT

Unpacked Size

9.28 kB

Total Files

10

Last publish

Collaborators

  • faboulaws