Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operation name to subscribe message #438

Closed
tomas-light opened this issue Jan 26, 2023 · 3 comments
Closed

Add operation name to subscribe message #438

tomas-light opened this issue Jan 26, 2023 · 3 comments
Labels
question Further information about the library is requested

Comments

@tomas-light
Copy link

tomas-light commented Jan 26, 2023

Story

As a client

I want to fast navigate in many messages in browser Network tab for web socket like:

image

You can see, there are a lot of messages sent via web socket, and without operation name it is too hard to observe all of them and find the needed one for debug

So I prepare code adjustments for that purpose:
master...TomasLight:graphql-ws:master

@enisdenjo
Copy link
Owner

Similar to #398.

I wouldn't add a new field to the subscribe message, I'd recommend instead using the generateID client option to ease up lookups during development. The argument receives the operation payload so you can construct whatever you want.

@tomas-light
Copy link
Author

@enisdenjo, what if I will have multiple messages with same ID (operation name)? Will it affect any internal implementations (maybe sync requests and responses or similar)?

@enisdenjo
Copy link
Owner

enisdenjo commented Jan 26, 2023

You can add something random to disambiguate the IDs during development. Roughly:

import { createClient } from 'graphql-ws';

const client = createClient({
  url: 'ws://dev-gen-id:4000/graphql',
  generateID: ({ operationName }) =>
    // operationName plus a random 4 character hash
    `${operationName}_${Math.random().toString(36).slice(-4)}`,
});

Do note that the GraphQL over WebSocket Protocol disallows multiple active operations with the same ID.

Repository owner locked and limited conversation to collaborators Jan 30, 2023
@enisdenjo enisdenjo converted this issue into discussion #440 Jan 30, 2023
@enisdenjo enisdenjo added the question Further information about the library is requested label Jan 30, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information about the library is requested
Projects
None yet
Development

No branches or pull requests

2 participants