Skip to content

Apollo GraphQL over WebSocket Subscription Authentication #1217

Discussion options

You must be logged in to vote

After much perusing of the source code, experimentation, and generally fumbling around, here's what I came up with:

Apollo Client

const webSocketClient = createClient({
	url: `ws${environment.serverSchemeSecure ? 's' : ''}://${environment.serverHost}:${environment.serverPort}${environment.graphQLpath}`,
	lazy: true,
	on: {
		closed: () => {
			this.apollo.client.defaultOptions.watchQuery.pollInterval = 0;
		},
		error: () => {
			this.apollo.client.defaultOptions.watchQuery.pollInterval = DefaultPollingInterval;
		},
	},
	connectionParams: () => {
		return this.authenticationService.accountsClient.getTokens(); // Add authToken to every connection
	},
});

Apollo Server

const webSocketServ…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KeithGillette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant