altair-graphql / altair

✨⚡️ A feature-rich GraphQL Client for all platforms.
https://altairgraphql.dev
MIT License
5.09k stars 314 forks source link

[BUG] subscriptionsProtocol not initialised correctly when passed in via RenderOptions using altair-static #2447

Closed MurrayFurtado closed 6 months ago

MurrayFurtado commented 6 months ago

Describe the bug

I am trying to launch altair-static with the subscriptionsProtocol set to 'graphql-sse'. All of my other render options are honoured by the UI but the Subscription Type dropdown doesn't change to show 'Graphql over SSE' instead remaining on 'Websocket'

To Reproduce Create an index.ts node server as follows:

import express, { Request, Response } from "express"; import * as http from "http"; import { getDistDirectory, renderAltair, RenderOptions } from "altair-static";

const app = express(); app.use(express.json()); app.use(express.static(getDistDirectory()));

app.get("/altair", (request, response) => { let opts: RenderOptions = { endpointURL: ${process.env.HOST}/graphql/request, subscriptionsProtocol: "graphql-sse", subscriptionsEndpoint: ${process.env.HOST}/graphql/stream, initialQuery: request.query.param as string, initialHeaders: { "Content-Type": "application/json", }, initialSettings: { theme: "dracula", }, preserveState: false, };

console.log("render", opts.subscriptionsProtocol); return response.send(renderAltair(opts)); });

const httpServer = http.createServer(app);

Expected behavior Subscription Type dropdown should change to show Graphql over SSE

Screenshots

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

imolorhe commented 6 months ago

I think you intend to use initialSubscriptionsProvider. subscriptionsProtocol is used to specify the protocol i.e. wss, https, etc. used for the subscriptions if the subscription URL is relative.

MurrayFurtado commented 6 months ago

You are correct, I was using the wrong parameter. I think your documentation around using altair-static could be improved if these config options were clearly explained somewhere.

imolorhe commented 6 months ago

The docs don't contain information about the altair-static options (since it can get stale quickly), but these should be available in the autocomplete options you get in your IDE! Also if there are some information missing in the docs, feel free to create a PR to update them. Doc contributions (among others) are always welcome! The docs are stored in altair-docs.