Is your feature request related to a problem?
I started with something like this (a nested resolver class):
public sealed class ArticleRelatedContentType : ObjectType<ArticleRelatedContent>
{
protected override void Configure(IObjectTypeDescriptor<ArticleRelatedContent> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor
.Field("players")
.ResolveWith<Resolvers>(_ => Resolvers.Players(default!, default!));
}
private class Resolvers
{
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public static IQueryable<Player> Players(
[Service] PlayerService playerService,
[Parent] ArticleRelatedContent relatedContent)
{
return playerService.GetPlayersByArticleId(relatedContent.Article.Id);
}
}
}
But the default! stuff bothers me. It seems like there should be some way to reference a method without a lambda. Maybe a Delegate?
I was also unable to make the class static, since the generic type argument cannot be static.
I'm now thinking of switching to something like this instead (just a method on the type class):
public sealed class ArticleRelatedContentType : ObjectType<ArticleRelatedContent>
{
protected override void Configure(IObjectTypeDescriptor<ArticleRelatedContent> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor
.Field("players")
.ResolveWith<ArticleRelatedContentType>(_ => Players(default!, default!));
}
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
private static IQueryable<Player> Players(
[Service] PlayerService playerService,
[Parent] ArticleRelatedContent relatedContent)
{
return playerService.GetPlayersByArticleId(relatedContent.Article.Id);
}
}
Again we have the lambda, and it also feels unnecessary to specify the current type in the generic.
The solution you'd like
Something simpler/cleaner, like:
descriptor
.Field("players")
.ResolveWith(Players);
If ResolveWith took a Delegate, could that work?
(I know that Resolve can also be used, but it can get messy to put all of the code into the Configure method.)
Product
Hot Chocolate
Is your feature request related to a problem?
I started with something like this (a nested resolver class):
But the
default!stuff bothers me. It seems like there should be some way to reference a method without a lambda. Maybe aDelegate?I was also unable to make the class static, since the generic type argument cannot be static.
I'm now thinking of switching to something like this instead (just a method on the type class):
Again we have the lambda, and it also feels unnecessary to specify the current type in the generic.
The solution you'd like
Something simpler/cleaner, like:
If
ResolveWithtook aDelegate, could that work?(I know that
Resolvecan also be used, but it can get messy to put all of the code into theConfiguremethod.)Product
Hot Chocolate