-
Notifications
You must be signed in to change notification settings - Fork 84
Property resolver with context #42
Comments
Can you give a use case of where this would be used? (I am new to GraphQL and Kotlin :)) |
The context could hold a security context which could be used to check permissions, e.g. restrict visibility of data. |
You can access the context by using
and
What I'm missing is that you can access the properties and context in the query itself. |
Ah, ok - Thanks!
Is this about mutations? |
Both, it's about accessing properties in each query/mutation. |
Ok, I got your point! I have not yet used mutations, so I did not stumble upon this problem. This 'accessRule' looks nice, but it prevents my use case. I do not want to do the permission checking in the graphql layer but a little bit deeper in the 'data' layer because a parallel REST-API also uses this 'data' layer. So I would like to have the possibility to pass the context (more precise: just the authorization part of it) to the 'data' layer. The suspendResolver/resolver function inside a query accepts a context object as parameter so that I can forward it:
Unfortunatlly, this is not possible with the property resolver. |
Hi @StefanHUB and @AlphonseSantoro You can use Context in resolvers of queries, extension properties and transformations (I have to update the documentation), see: KGraphQL/src/test/kotlin/com/github/pgutkowski/kgraphql/schema/SchemaBuilderTest.kt Line 321 in 780eda8
But if I understand correctly, you would like to declare "resolver" for Kotlin properties as well, with access to property and context? DSL example (not implemented yet): type<Actor> {
property(Actor::name) {
resolver { actor : Actor, ctx: Context ->
if(ctx.get<UserData>()?.canAccessActorName){
actor.name
} else {
throw UnauthorizedAccessException()
}
}
}
} Would this solve your use case? |
UPDATE: Working from locally built version. Probably last release is too old |
While it is possible to pass an optional context object to the "execute" function of the Schema which than will be propagated to the "suspendResolver"/"resolver" functions of the "query" block, I have not found a way how this context object gets passed to the property resolvers.
(using version 0.3.0)
The text was updated successfully, but these errors were encountered: