Many thanks for your effort! 😄
I'm trying to use filter with my resolver, but for now, my resolver is reversed like this:
[GraphQLResolverOf(typeof(User))]
[GraphQLResolverOf(typeof(Query))]
public class UserResolver
{
public IQueryable<User> Users([Parent]Query query)
{
return new EnumerableQuery<User>(new List<User>());
}
}
I've noticed that it can be achieved by
public class QueryType : ObjectType<Query>
{
protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
{
descriptor.Field("users").UseFiltering();;
base.Configure(descriptor);
}
}
will reversed resolver be able to achieve it?
Hi @snys98,
actually you can use type extensions for that. It is a little different but will still let you use a single resolver.
public class QueryTypeExtension : ObjectTypeExtension
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Name("Query");
descriptor.Field<UserResolver>(t => t.Users(default)).UseFiltering();
}
}
With type extensions you can decouple parts of your types.
The issue with providing filtering on an attributes base is that with the next version there are so many options with types that are not easily expressible through attributes.
Filtering is a middleware that also manipulates the type itself through the descriptor.
We sill are thinking about things like that...
[GraphQLResolverOf(typeof(User))]
[GraphQLResolverOf(typeof(Query))]
public class UserResolver
{
[UsePaging]
[UseFiltering]
[UseSorting]
public IQueryable<User> Users([Parent]Query query)
{
return new EnumerableQuery<User>(new List<User>());
}
}
The second concern that I have here is that order is important to middleware. Would people understand that a paging attribute has to come at the top and that an invalid order here could lead to invalid data processing?
But it would be cool to have a middleware attribute :)
@PascalSenn what do you think.
Yeah, that's what I want, good for ObjectTypeExtensions. Additionally, maybe kind of off topic, actually I'm trying to encapsulate my graphql types and resolvers into different modules(WIP).

And connect them through DI like this:
startup.cs

AppModule.cs

Do you have some plan of making a module system? 😄
I'm up for attributes.
We could do this.
We might as well consider a way of controlling the execution order of middlewares.
So that the middlewares could just be attached and they would be executed in the right order in every case.
Do you have some plan of making a module system? 😄
Not one that I would be aware of. We do something similar in one of our projects at work. We basically have builder that composes the repository and the types.
This will be even easier when there are non generic methods for UseFiltering,UseSorting, and UsePageing #1178
@snys98 what do you actually mean with module system? you want to collect the types from the di and putt them together?
@michaelstaib sorry, I've been outside for days.
you want to collect the types from the di and putt them together?
yeah, that's it. I want to separate my type&resolver definition to different modules, collect them to di "module by module", and merge them when build the schema.
Closing as these attributes are in place
This will be even easier when there are non generic methods for UseFiltering,UseSorting, and UsePageing #1178
@snys98 if you are still interestes into collect them to di "module by module", and merge them when build the schema. you may open a new issue specific to this :)