Comments (8)
Hi @StefanHUB and @AlphonseSantoro
You can use Context in resolvers of queries, extension properties and transformations (I have to update the documentation), see:
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?
from kgraphql.
Can you give a use case of where this would be used? (I am new to GraphQL and Kotlin :))
from kgraphql.
The context could hold a security context which could be used to check permissions, e.g. restrict visibility of data.
from kgraphql.
You can access the context by using
type<Post>{
property(Post::id){
accessRule { post, ctx ->
if(post.id == ctx.get<String>()) null else IllegalAccessException()
}
}
}
and
query("black_mamba") {
resolver { -> Player("KOBE") }
accessRule { ctx -> if (ctx.get<String>().equals("LAKERS")) null else IllegalAccessException() }
}
What I'm missing is that you can access the properties and context in the query itself.
e.g. I want a user to be able to read all posts but i dont want the user to edit posts of other users
from kgraphql.
Ah, ok - Thanks!
.. but i dont want the user to edit posts of other users
Is this about mutations?
from kgraphql.
Is this about mutations?
Both, it's about accessing properties in each query/mutation.
When using the first example I gave, the access rule applies to all queries/mutations to that type. As of now i can't see there is any property access on query/mutation level.
from kgraphql.
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:
query("timeEntries") {
suspendResolver { ctx: Context, year: Int?, month: Int?, userId: UserId?, topicFK: Int?, timeEntryTypeFK: Int? ->
// forward "ctx" to the "data" layer.
}
}
Unfortunatlly, this is not possible with the property resolver.
from kgraphql.
UPDATE: Working from locally built version. Probably last release is too old
@pgutkowski This works, but still there is a problem -- schema became invalid. I am getting this in qraphiql:
Error: Invalid or incomplete schema, unknown type: null. Ensure that a full introspection query is used in order to build a client schema.
As I understand this is because Context become input type which is not defined.
If I am trying to define it as Input Type am getting an error that generic classes are not supported from handleInputValues method.
Do you have any suggestions how to fix this?
from kgraphql.
Related Issues (20)
- Extension property not working HOT 1
- Support for suspendable property resolvers HOT 2
- There is no instruction to help a new user to start the server and the client in this example. How can I run the server and start query? HOT 2
- LocalDate coercion issue HOT 2
- Support for suspendable schema execution HOT 1
- Scalar types within variables not working HOT 1
- How would I handle query/mutation authentication? HOT 4
- Print Schema? HOT 1
- Adding Context parameter to resolver causes errors in introspection HOT 3
- Fragments not resolving correctly on same data node
- Nested Fragments fail with property does not exist HOT 2
- LocalDate when passed as query variable HOT 1
- Leaking top level
- Is this the right way with using resolvers on a type? HOT 2
- Support for suspendable unionProperty resolvers
- Implement a DataLoaderDSL for batching
- Caused by: java.lang.NoClassDefFoundError: kotlinx/coroutines/experimental/CommonPool HOT 1
- When overwriting a property, the GraphQL repeats the original property unless ignored
- release 0.3.1 build? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kgraphql.