Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

feat: subscriptions refinements and comments #15

Closed
wants to merge 9 commits into from
Closed

Conversation

darahayes
Copy link
Contributor

This PR adds some really nice subscriptions refinements.

Take a look at the two examples provided.

  • subscriptions.js - demonstrates the basic setup needed for subscriptions. In this mode, all subscriptions must be authenticated

  • subscriptions_advanced.js - demonstrates how we can use new KeycloakSubscriptionHandler({protect: false}) so that onSubscriptionConnect will not automatically throw an error if no auth related connectionParams are provided. This makes it possible to add authentication/authorization on individual subscription resolvers. For example you could have both public and private subscriptions.

In both scenarios, context.kauth in the subscription resolvers will work the exact same as in regular resolvers thanks to the KeycloakSubscriptionContext class. (KeycloakSubscriptionContext and KeycloakContext are now extensions of the KeycloakContextBase which provides the common functionality. This could also be used in future if we needed to support context from something that isn't express).

These improvements in how the context is built means that it is now possible to reuse the existing hasRole and auth resolver middlewares on subscription resolvers. Here's an example:

const { auth } = require('keycloak-connect-graphql')

const resolvers = {
  Subscription: {
    taskAdded: {
      subscribe: auth(() => pubsub.asyncIterator(TOPIC))
    },
    taskDeleted: {
      subscribe: hasRole('admin')(() => pubsub.asyncIterator(TOPIC))
    }
  }
}

@darahayes
Copy link
Contributor Author

Closing in favour of some smaller PRs

@darahayes darahayes closed this Jul 10, 2019
@darahayes darahayes deleted the comments branch July 11, 2019 13:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant