Graphql - Filter where object is null or non existant

Viewed 454

I'm using NET5 with Hotchocolate 12 as graphql middleware.

I have the following setup for my query type:

[UseDbContext(typeof(AppDbContext))]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Domain> GetDomains([ScopedService] AppDbContext context) => context.Domain;

The domain entity looks as follows:

public class Domain
{
    public string Name { get; set; }
    public Domain? ParentDomain{ get; set; }
    public List<Domain>? ChildDomains { get; set; } = new();
}

Challenge is I want to construct a graphql query that returns all Domains where the ParentDomain is non existant, is there a way to construct such query?

E.g.

query {
  domains (where: {
        ParentDomain: null
  }) {        
    name
  }
}

Appreciate the guidance

0 Answers
Related