1

I have code:

import { ApolloClient, ApolloLink, InMemoryCache, from, HttpLink } from '@apollo/client';
import { WebSocketLink } from '@apollo/client/link/ws';
import { SubscriptionClient } from 'subscriptions-transport-ws'; 
import { HOST, SSL_ENABLED } from './config';

const uri = (protocol: string) => `${protocol}://${HOST}/graphql`;

export default function apolloClient(token?: string | null): any {
    const link = from([
        new ApolloLink((operation, forward) => { 
            operation.setContext({
                headers: {
                    ...token && { Authorization: `Bearer ${token}` } || {},
                },
            });

            return forward(operation);
        }),
        new WebSocketLink(new SubscriptionClient(uri(`ws${SSL_ENABLED ? 's' : ''}`), {
            reconnect: true,
        })),
        new HttpLink({ uri: uri(`http${SSL_ENABLED ? 's' : ''}`) }),
    ]);

    return new ApolloClient({
        link,
        cache: new InMemoryCache(),
    });
}

And I am getting an warning You are calling concat on a terminating link, which will have no effect. Also any request is not send from my application to my api.

When I removed

        new WebSocketLink(new SubscriptionClient(uri(`ws${SSL_ENABLED ? 's' : ''}`), {
            reconnect: true,
        })),

Everything is fine and app is working (sending request) without any warning.

What is wrong?

yihereg819
  • 131
  • 1
  • 6

0 Answers0