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
4.96k stars 722 forks source link

Bug: UseProjections prevents UseFilter from working in nested collections #7066

Open JonnyIV opened 1 month ago

JonnyIV commented 1 month ago

Product

Hot Chocolate

Version

13.9.0

Link to minimal reproduction

https://github.com/JonnyIV/GraphQlPagingFilterIssue/blob/master/GraphQlPagingFilterIssue/Query.cs

Steps to reproduce

code:

public class Query
{
    [UseProjection]
    public IQueryable<Movie> GetMovie() => new Movie[] { new() { Name = "Star Wars" } }.AsQueryable();
}
public class Movie
{
    public string Name { get; set; } = "";

    [UseFiltering]
    public IQueryable<Character> GetCharacters() => new Character[] new() { Name = "Luke Skywalker" }, new() { Name = "Darth Vader" }, new() { Name = "Princess Leia" } }.AsQueryable();
}
public class Character
{
    public string Name { get; set; } = "";
}

query:

query {
  movie {
    name
    characters(where: { name: { startsWith: "Darth" } }) {
      name
    }
  }
}

What is expected?

{
  "data": {
    "movie": [
      {
        "name": "Star Wars",
        "characters": [
          {
            "name": "Darth Vader"
          }
        ]
      }
    ]
  }
}

What is actually happening?

{
  "data": {
    "movie": [
      {
        "name": "Star Wars",
        "characters": [
          {
            "name": "Luke Skywalker"
          },
          {
            "name": "Darth Vader"
          },
          {
            "name": "Princess Leia"
          }
        ]
      }
    ]
  }
}

Relevant log output

No response

Additional context

No response

andhallberg commented 2 weeks ago

I am facing the same issue.

JonnyIV commented 2 weeks ago

The workaround I am using is disabling projections on the parent element. It is not optimal but suffices in my case until this is fixed.

andhallberg commented 2 weeks ago

Thanks @JonnyIV, I was trying the same thing. Unfortunately I have some properties on the object in the child collection that needs projection on the parent element to get their auto-generated resolvers (via EF Core) to work properly.