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

Pass InitialPayload from Federated Subscriptions to Subgraphs #803

Open
IsabelFreitas-catapult opened this issue May 17, 2024 · 7 comments
Labels
internally-reviewed Internally reviewed

Comments

@IsabelFreitas-catapult
Copy link

My client uses the initialPayload to pass custom header information to the websocket connection, I can intercept the payload at the federated level but it isn't being passed on to the subgraphs where I need it

@cordjr
Copy link

cordjr commented May 17, 2024 via email

@IsabelFreitas-catapult
Copy link
Author

IsabelFreitas-catapult commented May 20, 2024

@cordjr Thank you for getting back to me
inws.go I have set up a the WithInitFunc HandleWebsocket that adds the values of the initialPayload to context, however after this point those values disappear from the context

func HandleWebsocket(done chan bool, errChan chan error, conn net.Conn,
	executorPool *subscription.ExecutorV2Pool, logger *slog.Logger) {
	defer func() {
		if err := conn.Close(); err != nil {
			logger.Error("http.HandleWebsocket(): could not close connection to client.", err)
		}
	}()

	websocket.Handle(
		done,
		errChan,
		conn,
		executorPool,
		websocket.WithProtocol(websocket.ProtocolGraphQLWS),
		websocket.WithInitFunc(func(ctx context.Context,
			initPayload websocket.InitPayload) (context.Context, error) {
			headers := http.Header{}
			initPayload.GetString("X-Email")
			headers.Add("X-Email", initPayload.GetString("X-Email"))
			ctx = context.WithValue(ctx, "headers", headers)
			return ctx, nil
		}),
		websocket.WithCustomSubscriptionUpdateInterval(50*time.Millisecond),
		websocket.WithCustomKeepAliveInterval(3600*time.Second),
	)
}

any chance you could share your implementation?

@jensneuse jensneuse added the internally-reviewed Internally reviewed label May 21, 2024
@cordjr
Copy link

cordjr commented May 21, 2024 via email

@IsabelFreitas-catapult
Copy link
Author

github.com/wundergraph/graphql-go-tools v1.67.2
and the Handle function I am using is this one https://github.com/wundergraph/graphql-go-tools/blob/master/pkg/subscription/websocket/handler.go

@cordjr
Copy link

cordjr commented May 21, 2024 via email

@jensneuse
Copy link
Member

Just stepping into the discussion, you could use this test and debug through it to see how we're solving this problem in Cosmo Router to get some inspiration on how the library can be used: https://github.com/wundergraph/cosmo/blob/4077ab4a01f03c1c3dd7e6167255d3d8da80e3dc/router-tests/websocket_test.go#L406

@cordjr
Copy link

cordjr commented May 22, 2024 via email

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

No branches or pull requests

3 participants