Skip to content
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

Subscription connection parameters support #360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HaraldNordgren
Copy link
Contributor

@HaraldNordgren HaraldNordgren commented Nov 14, 2024

Adds support for subscription (websocket) connection parameters support.

We are having an issue with authorization when using subscriptions in genqlient. Our mobile app team is using Apollo for GraphQL requests, and Apollo seems to sends its auth in a way that is different from how genqlient does it:

https://www.apollographql.com/docs/react/data/subscriptions#5-authenticate-over-websocket-optional

This is causing a problems, because we use genqlient for testing the backend. It seems that the way Apollo is implemented, authentication (and other headers) are not actually sent as HTTP headers, but as connection parameters instead.

I have:

  • Written a clear PR title and description (above)
  • Signed the Khan Academy CLA
  • Added tests covering my changes, if applicable
  • Included a link to the issue fixed, if applicable
  • Included documentation, for new features
  • Added an entry to the changelog

//
// connectionParams is a map of connection parameters to be sent to the server
// during the initial connection handshake.
func NewClientUsingWebSocketWithConnectionParams(endpoint string, wsDialer Dialer, headers http.Header, connParams map[string]any) WebSocketClient {
Copy link
Contributor Author

@HaraldNordgren HaraldNordgren Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there was never a a release that includes NewClientUsingWebSocket, we should be free to update the signature if we want, and possible only have one function:

func NewClientUsingWebSocket(endpoint string, wsDialer Dialer, headers http.Header, connParams map[string]any) WebSocketClient

@HaraldNordgren
Copy link
Contributor Author

HaraldNordgren commented Nov 14, 2024

A big gotcha regarding HTTP headers and connection parameters, that I realized recently, is that websocket requests in 99desgins gqlgen enter a different path, going through here:

	gqlgenServer.AddTransport(transport.Websocket{
		InitFunc: func(ctx context.Context, initPayload transport.InitPayload) (context.Context, *transport.InitPayload, error) {
			// initPayload contains connection parameters
		},
	})

than the middleware path that would normally be expected:

	r.With(ah.VerifyAuthMiddleware).Method(http.MethodPost, "/v1", c.GraphServer)
	r.With(ah.VerifyAuthMiddleware).Method(http.MethodGet, "/v1", c.GraphServer)

@HaraldNordgren HaraldNordgren changed the title Allow setting websocket connection parameters Subcription connection parameters support Nov 16, 2024
@HaraldNordgren HaraldNordgren changed the title Subcription connection parameters support Subscription connection parameters support Nov 16, 2024
@HaraldNordgren
Copy link
Contributor Author

Ping @benjaminjkraft and @matthieu4294967296moineau, do you think it would be possible to get a quick look here? 🤗

@HaraldNordgren
Copy link
Contributor Author

Ping @benjaminjkraft 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant