Skip to content

Any example of graphql-ws gateway? #383

Answered by enisdenjo
andreisoktoev asked this question in Q&A
Discussion options

You must be logged in to vote

I recommend using graphql-mesh for constructing GraphQL gateways, it has built in support for graphql-ws as the subscription transport.

However, here's a simple proxy implementation that forwards all requests to an upstream graphql-ws server (untested):

import { ExecutionArgs, ExecutionResult } from 'graphql';
import { WebSocket, WebSocketServer, CloseEvent } from 'ws';
import { Client, createClient, SubscribePayload } from 'graphql-ws';
import { useServer } from 'graphql-ws/lib/use/ws';

const server = new WebSocketServer({
  port: 4000,
  path: '/graphql',
});

type GatewayExecutionArgs = ExecutionArgs & {
  contextValue: {
    client: Client;
    payload: SubscribePayload;
  };
};

use…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by enisdenjo
Comment options

You must be logged in to vote
1 reply
@enisdenjo
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #380 on August 09, 2022 15:07.