Accept Promise to allow Subscription validation & authorization #4690
Replies: 2 comments 2 replies
-
+1 for this feature. Accepting Promise looks like very easy and intuitive way to authorize or pre-process any tasks per subscription. |
Beta Was this translation helpful? Give feedback.
-
Does it already work as you describe? Tracing code
TL;DR what folks have been asking for since at least June 2018 seems like it might exist today (and possibly since What about
|
Beta Was this translation helpful? Give feedback.
-
The Resolver functions for Queries and Mutations can return Promises, which allows them to asynchronously validate input and perform authorization, rejecting the Query or Mutation Promise if either fails or fulfilling it if the validation and authorization pass.
However, it appears that a Subscription Resolver function must only return an AsyncIterator. As suggested in issue #1248, "Best practice to authorize subscriptions in Apollo Server 2", I think the most flexible and consistent way to allow Subscription validation and authorization would be to allow Subscription Resolver functions to also return a Promise for an AsyncIterator, with a rejected Promise cancelling the client Subscription request.
Such a change would also allow the
AsyncIterator
& itswithFilter
function to be generated based on async operations, allowing for more sophisticated server-side Subscription configuration.Absent that capability, how may one best validate and authorize a Subscription request?
Beta Was this translation helpful? Give feedback.
All reactions