ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.23k stars 744 forks source link

ValidatePipelineOrder=false wont work #5883

Closed barnuri-cp closed 1 year ago

barnuri-cp commented 1 year ago

Is there an existing issue for this?

Product

Hot Chocolate

Describe the bug

when setting ValidatePipelineOrder=false, its probably not populate to MiddlewareValidationTypeInterceptor because it keep throwing errors of invalid order

Steps to reproduce

var graphqlBuilder = servicesCollection.AddGraphQLServer(); graphqlBuilder = graphqlBuilder.AddProjections(); graphqlBuilder = graphqlBuilder.AddFiltering(); graphqlBuilder = graphqlBuilder.AddSorting(); graphqlBuilder = graphqlBuilder.SetOptions(new() {ValidatePipelineOrder =false}); graphqlBuilder = graphqlBuilder.ModifyOptions(c => c.ValidatePipelineOrder = false);

[UseDbContext(typeof(User))] [UseSorting] [UsePaging] [UseProjection] [UseFiltering] public IQueryable GetUser([Service] Repo repository) => repository.Users;

Relevant log output

No response

Additional Context?

No response

Version

13

PascalSenn commented 1 year ago

@barnuri-cp Reproduced, Workaround, do not use SetOptions just use ModifyOptions

Also, why do you want to do this?

barnuri-cp commented 1 year ago

@PascalSenn im writing a feature to distinct the result of IQueryable, and i put it after the projections and its works good, but the sort happen before, and i need it after the distict because i wanted the distinct results to be sorted so sort need to be in the end

michaelstaib commented 1 year ago

It also will not work... sorting cannot work after paging since paging is not outputing a list or queryable.

michaelstaib commented 1 year ago

But you could handle the order in your resolver.

barnuri-cp commented 1 year ago

@michaelstaib can you give me an example ? i want one resolver for the whole app, dont want to config it each method

michaelstaib commented 1 year ago

How do you want to have one resolver for different types?

HC 13 allows you tow wrap attributes in attributes and introduce a new pipeline in there. The new pipeline can do the apply on the queryable.

barnuri-cp commented 1 year ago

@michaelstaib yeah i want to make it generic, dont wont to work hard it every type, like all other works for example if i had a way to just receive the IQueryable before everything else is running i can do it generic IQueryable q q = q.Filter(context).Projection(context).Distinct().Sort(context)

barnuri-cp commented 1 year ago

@michaelstaib nice ! find that

public class UseSearchAttribute : DescriptorAttribute
{
    protected override void TryConfigure(IDescriptorContext context, IDescriptor descriptor, ICustomAttributeProvider element)
    {
        ApplyAttribute(context, descriptor, element, new UseSortingAttribute());
        ApplyAttribute(context, descriptor, element, new UsePagingAttribute());
        ApplyAttribute(context, descriptor, element, new UseProjectionAttribute());
        ApplyAttribute(context, descriptor, element, new UseFilteringAttribute());
    }
}

thanks for the help and the quick response !!!