Skip to content

Send custom headers please #267

Answered by enisdenjo
chris-carrington asked this question in Q&A
Discussion options

You must be logged in to vote

Hey there, setting custom headers is not possible in browsers; however, the User-Agent header is automatically set there anyway.

Passing custom headers with Node's ws library is possible though, but not recommended (given the lack of documentation around it). Here's how you can make a WebSocket implementation with custom headers and pass it to graphql-ws:

import WebSocket from 'ws'; // yarn add ws
import { createClient } from 'graphql-ws';

class MyWebSocket extends WebSocket {
  constructor(address, protocols) {
    super(address, protocols, {
      headers: {
        // your headers go here
        'User-Agent': 'graphql-ws client',
      },
    });
  }
}

const client = createClient({
  

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@enisdenjo
Comment options

@ahmedmohamedfci
Comment options

@PopBot
Comment options

@enisdenjo
Comment options

@xzecakular
Comment options

Answer selected by enisdenjo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #266 on November 15, 2021 09:09.