Skip to content

How to use graph-ws instead #3

@ziedHamdi

Description

@ziedHamdi

Hi,

Thanks for this project that simplifies the burden on how to setup subscription. My issue is that it relies on subscriptions-transport-ws which is deprecated to the benefit of https://the-guild.dev/blog/graphql-over-websockets as mentioned on their npm page:

The subscriptions-transport-ws library is not being actively maintained. It is recommended that you use the graphql-ws library instead. For details read the GraphQL over WebSockets announcement.

So I'm struggling about how to get the roots of my gql schema from the object returned by schemaComposer.buildSchema()

subscriptionServer.js

import ws from 'ws'; // yarn add ws
import { useServer } from 'graphql-ws/lib/use/ws';
const GraphQlSchema = require('./graphql').default

//redis must be running
const server = new ws.Server({
    port: 4001,
    path: '/subscribe',
});

useServer(
    // from the previous step
    { schema: GraphQlSchema, roots: GraphQlSchema },
    server
);

console.log('Listening to port 4001');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions