-
Notifications
You must be signed in to change notification settings - Fork 299
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
Can't use Spring Security annotation when injecting DataLoader and returning a CompletableFuture #343
Comments
Interestingly enough converting to a mono seems to work; @SchemaMapping
@PreAuthorize("@permissionEvaluator.hasPermission(authentication, #merchant.id, 'Merchant', 'read')")
fun dashboardForDate(
merchant: Merchant,
@Argument date: LocalDate?,
merchantLoader: MerchantDataLoader
): Mono<Dashboard> = merchantLoader.load(merchant.id).thenApply {
if (it == null) throw EntityNotFoundException()
Dashboard(date, it)
}.toMono() Although I'm not sure if this is coincidental, or that this is supposed to work. |
The method needs to return a reactive type for reactive context to propagate. So this is expected, but you're bringing up a good point that our examples with injecting a |
So returning a mono is supposed to work for dataloaders? In comparison; awaiting the And a |
Yes that should work. |
Alright, good to know it's spring graphql specific. |
Probably so, but need to investigate. |
@rstoyanchev I'm not sure about whether the combination with Spring Security annotations now works, since we stopped using that because it didn't work well together with Spring R2DBC (overfetching data because it doesn't have a cache like JPA does). So also the need for it disappeared for us. |
Closing for now. |
I'm having trouble combining DataLoaders with Spring Security;
My scenario;
For GraphQL Java being able to dispatch the dataloader the method has to return the
CompletableFuture
, but for the@PreAuthorize
annotation it "must return an instance of org.reactivestreams.Publisher (i.e. Mono / Flux) or the function must be a Kotlin coroutine function".I've also tried making it a
suspend fun
, while still returning theCompletableFuture
, but then I get an error likedoes not match the type of the source Object 'class java.util.concurrent.CompletableFuture'
, which makes sense because my controller is not expecting theCompletableFuture
.Is my assumption correct, or is there a way around this that I don't know about?
The text was updated successfully, but these errors were encountered: