Handle Apollo subscription onConnect #111
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduced a
ConnectionSubscriptionListener
that provides the ability to handle theonConnect
. See also: https://www.apollographql.com/docs/graphql-subscriptions/authentication.html.If
onConnect
returns anObject
it is set in theSession.userProperties
, which in turn is used now when building theGraphQLContext
. It's currently available throughGraphQLContext.getConnectResult()
.GraphQLContext
could be improved by splitting it up in separate context implementations instead of this version, but left that for a different case.The default implementation provided here does nothing. If you want to add authorization using these features you would have to provide an implementation of
ApolloSubscriptionConnectionListener
that would handle the authorization and throws aRuntimeException
if authorization wasn't successful. If the user could be authenticated it could return a custom object representing the principal which in turn would be made available in theGraphQLContext
.By providing your own custom
GraphQLContextBuilder
as well you could align it with your own user types obviously.