-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Hello, I see that currently, to access the Context
or Execution.Node
we have to do something like:
resolver { foo: String, ctx: Context -> /* ... */ }
which implies that we need to add rules to the schema parser to ignore those classes when kgraphql is reflecting the FunctionWrapper<*>
's arguments:
So, if I'm hypothetically working on #68, and I want to add a new type that should not be introspected (let's say List<Throwable>
), I should create a wrapper class (like Context
is just a wrapper for Map<Any, Any>
), ignore this class in the schema introspection, and inject an object of this class into the FunctionWrapper
's arguments when invoking it... Am I Right?
Kotlin supports Receiver Functions (https://kotlinlang.org/docs/lambdas.html#function-types), which, are, for instance, A.(B)->C
where in this lambda, A
will be the this
context of the execution.
So, why instead of injecting Context
s and Execution.Node
's in the Resolvers, we create a ExecutionScope
class and make this class the receiver of the resolver
s?
class ExecutionScope(val context: Context, val node: Execution.Node, val errors: MutableList<Throwable>)
// This, obviously adapted to work with ``FunctionWrapper``
fun <A, B> resolver(ExecutionScope.(A)->B: body) { ... }
resolver { foo: String ->
/* context, node and errors are accessible here. */
/* We can do something like errors += Throwable("bondia") */
}
This will make it much easier and cleaner to work with contexts and other runtime wrappers.
I have been thinking about this while reading the code, but I did not attempt to do anything yet, do you @jeggy thinks that this issue makes sense? Any advices?