-
-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaner options for ResolveWith and static classes/methods #5445
Comments
Why do you not use the |
OR do you mean minimal API like? |
For static you could just use resolve btw |
How would think about this? public sealed class ArticleRelatedContentType : ObjectType<ArticleRelatedContent>
{
protected override void Configure(IObjectTypeDescriptor<ArticleRelatedContent> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor
.Field("players")
.Resolve(
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
([Service] PlayerService playerService,
[Parent] ArticleRelatedContent relatedContent)
=> playerService.GetPlayersByArticleId(relatedContent.Article.Id));
}
} you could in this case even do a static delegate. |
CC @PascalSenn |
Trying to switch it now to something like: descriptor
.Field("players")
.Resolve((IResolverContext context) =>
{
var playerService = context.Service<PlayerService>();
var relatedContent = context.Parent<ArticleRelatedContent>();
return playerService.GetPlayersByArticleId(relatedContent.Article.Id);
})
.UsePaging()
.UseProjection()
.UseFiltering()
.UseSorting(); And getting this for some reason:
Maybe I'm doing something stupid.
I feel like it looks much easier to read as a separate method. I assume by your answer that it's not technically possible to take a |
Can you specify some code ... like how you would want to write it? |
I did, under descriptor
.Field("players")
.ResolveWith(Players); Where I haven't written a ton of C#, so forgive me if this is a silly question. |
its probably what I suggested ... the above, which also the minimal API uses compiles delegates... I will have a look at it ... It only works since .NET 6. But I do not know... if it can infer if from the method. |
@glen-84, problem solves very easy with simple extension methods. internal static class DescriptorExtensions
{
public static IObjectFieldDescriptor Field(this IObjectTypeDescriptor descriptor, Delegate @delegate)
=> descriptor.Field(@delegate.Method);
public static IObjectFieldDescriptor Field<TRuntimeType>(this IObjectTypeDescriptor<TRuntimeType> descriptor, Delegate @delegate)
=> descriptor.Field(@delegate.Method);
public static IObjectFieldDescriptor ResolveWith(this IObjectFieldDescriptor descriptor, Delegate @delegate)
=> descriptor.ResolveWith(@delegate.Method);
} Then descriptor
.Field(Resolvers.Players);
// -- or --
descriptor
.Field("myname")
.ResolveWith(Resolvers.Players); @michaelstaib, does it matter in terms of performance if we provide |
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
ResolveWith
took aDelegate
, could that work?(I know that
Resolve
can also be used, but it can get messy to put all of the code into theConfigure
method.)Product
Hot Chocolate
The text was updated successfully, but these errors were encountered: