Solus
Solus

Reputation: 41

Error: Cannot use namespace 'Observable' as a type. (apollo-link, typescript)

i am trying to create a graphql subcription with hasura, follow this example: Boilerplate to test GraphQL subscriptions using nodejs, just added types for trypescript, if i run it directly with nodemon works fine, and gets me the data i want but if try to make a tsc i get the following errors:

enter image description here

and my code for the subscription is:

/*****  Setup a GraphQL subscription observable  ******************************/

import { DocumentNode, execute, GraphQLRequest } from 'apollo-link';
import { WebSocketLink } from 'apollo-link-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import ws from 'ws';

const getWsClient = (wsURL: string) => {
    const client = new SubscriptionClient(
        wsURL, {
            reconnect: true, connectionParams: () => {
                return {
                    headers: {
                        'x-hasura-admin-secret': process.env.HASURA_GRAPHQL_ADMIN_SECRET
                    }
                }
            }
    }, ws
    );
    return client;
};

// wsURL: GraphQL endpoint
// query: GraphQL query (use gql`` from the 'graphql-tag' library)
// variables: Query variables object
const createSubscription = (wsURL: string, query: DocumentNode, variables: Record<string, any>) => {
    const link = new WebSocketLink(getWsClient(wsURL));
    return execute(link, { query, variables } as GraphQLRequest);
};

export default createSubscription

I already updated typescript for "nodemon": "^2.0.15", "ts-node": "^10.2.1", "typescript": "^4.4.2"

does any one have any ideas?

Thanks in advance.

Upvotes: 1

Views: 470

Answers (0)

Related Questions