Open tekacs opened 7 years ago
Yeah, unfortunately there is no out-of-the-box support. One thing that I can recommend you to check is a ReplaceField
macro setting. Here is an example:
val tpe = deriveObjectType[Ctx, TestSubject](
ReplaceField("foo", Field("foo", ListType(StringType), resolve = Projector((ctx, proj) ⇒ {
// resolve logic goes here
}))))
Thanks for this! Would you be opposed to a pull request refactoring the way Projector` works, if it were possible to make both the current API and this approach work?
(more generally it would be nice to make more Sangria features work with macro derivation, since derived interfaces leave the underlying functions far easier to reuse)
It would be cool if you could check it out! At the moment I'm not quite sure how to signal that particular field needs a projection (it's probably only relevant for methods, since the projection will be passed as an argument). Also projection should accept an argument (the depth).
If you have ideas, I would be happy to discuss them. Especially how the end-user API would look like.
I've tried taking a quick look about to see how possible this is, but I was wondering - is it possible to refactor
Projector
in such a way that it can be passed to methods generated byderiveContextObjectType
in the same way that Context is?As it stands, where
Projector
overrides theresolve
function, I can't immediately see a way to make this work short of refactoring its mechanism.