Replies: 3 comments 15 replies
-
This is a really nice feature that would be very useful to add! ❤️ Please create a dedicated feature request, with a proposed API and some details of the goal you would like to achieve 😉 |
Beta Was this translation helpful? Give feedback.
2 replies
-
what you could do is something like this: @Resolver(() => GraphTimeseries)
export default class GraphTimeseriesResolver implements ResolverInterface<GraphTimeseries> {
@FieldResolver()
async asset(@Root() timeseries: GraphTimeseries, @Ctx() source: Source) {
timeseries.asset ??= source.getAssetById(timeseries.assetId);
return timeseries.asset;
}
@FieldResolver()
async eventsOwnerIds(@Root() timeseries: GraphTimeseries, @Ctx() source: Source, @Info() info) {
timeseries.asset ??= source.getAssetById(timeseries.assetId);
const asset = await timeseries.asset;
}
} you can also create a resolver decorator for this: @Resolver(() => GraphTimeseries)
export default class GraphTimeseriesResolver implements ResolverInterface<GraphTimeseries> {
@FieldResolver()
@FetchAsset(({ root }) => root.assetId)
async asset(@Root() timeseries: GraphTimeseries, @Ctx() source: Source) {
return timeseries.asset;
}
@FieldResolver()
@FetchAsset(({ root }) => root.assetId)
async eventsOwnerIds(@Root() timeseries: GraphTimeseries, @Ctx() source: Source, @Info() info) {
const asset = await timeseries.asset;
}
} |
Beta Was this translation helpful? Give feedback.
4 replies
-
I managed to get this working by modifying @backbone87 answer. I just put the Promise into
|
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
Is there any way for async resolvers to depend on each other? I have this situation here popping up all over the place: https://gist.github.com/annitya/fd156bc98976219c1e108f3267560ec6
eventsOwnerIds depends on the result from the asset-resolver, but it is unavailable.
A lot of the fields on the various entities are results of async api-calls.
It's a shame that I'm unable to use half of my objects :-/
Would it be possible to create a "dependsOn" decorator using this library or something similar: https://github.com/lucasconstantino/graphql-resolvers?
Beta Was this translation helpful? Give feedback.
All reactions