🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-ez/plugin-websockets

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-ez/plugin-websockets

Integration with:

0.11.3
latest
Source
npm
Version published
Weekly downloads
423
-0.94%
Maintainers
1
Weekly downloads
 
Created
Source

@graphql-ez/plugin-websockets

Integration with:

  • GraphQL over WebSocket Protocol - graphql-ws
  • Legacy Support for subscriptions-transport-ws (using a fork called subscriptions-transport-ws-envelop)

Usage

import { ezWebSockets } from '@graphql-ez/plugin-websockets';

const ezApp = CreateApp({
  ez: {
    plugins: [
      ezWebSockets('adaptive'),
      // ...
    ],
  },
  // ...
});
export type WebSocketOptions =
  // If you enable both protocols, it will automatically adapt to the correct protocol based on the client
  | {
      subscriptionsTransport?:
        | {
            rootValue?: any;
            validationRules?: readonly any[] | ((context: ValidationContext) => any)[];
            onOperation?: Function;
            onOperationComplete?: Function;
            onDisconnect?: Function;
            keepAlive?: number;
          }
        | boolean;
      // Check https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/server.serveroptions.md
      graphQLWS?: Omit<GraphQLWSOptions, 'schema' | 'execute' | 'subscribe' | 'context' | 'validate' | 'onSubscribe'> | boolean;
      wsOptions?: {
        verifyClient?:
          | ((
              info: {
                origin: string;
                secure: boolean;
                req: IncomingMessage;
              },
              callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void
            ) => void)
          | ((info: { origin: string; secure: boolean; req: IncomingMessage }) => boolean);
        clientTracking?: boolean;
        perMessageDeflate?: boolean | PerMessageDeflateOptions;
        maxPayload?: number;
      };
    }
  // Only use graphql-ws library protocol
  | 'new'
  // Only use legacy subscriptions-transport-ws protocol
  | 'legacy'
  // Automatically use the correct protocol based on the client, the default value
  | 'adaptive';

Next.js Compatibility

This plugin is not supported for Next.js, since it follows the serverless architecture, and Websockets are not supported in serverless.

If you really need websockets for Next.js, you can use libraries like fastify-nextjs to use Fastify as a custom server for Next.js.

FAQs

Package last updated on 04 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts