How do you load nested types? For example, I have fairly simple model that looks like:
public class Customer
{
public string CustomerId { get; set; }
public string Forename { get; set; }
public string LastName { get; set; }
public ICollection<Order> Orders { get; set; }
}
public class Order
{
public string OrderId { get; set; }
public string CustomerId { get; set; }
}
My query does the following (returns hardcoded data)
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Customer> Customers()
{
var customers = new List<Customer>
{
new()
{
CustomerId = "1", Forename = "Foo", LastName = "Blah",
Orders = _orderService.GetOrdersByCustomerId("")
},
new()
{
CustomerId = "2", Forename = "Bar", LastName = "BlahBlah",
Orders = _orderService.GetOrdersByCustomerId("")
}
};
return customers.AsQueryable();
}
The _orderService
its calling is returning hardcoded data:
public ICollection<Order> GetOrdersByCustomerId(string customerId)
{
return new List<Order>
{
new() { OrderId = $"{customerId}-99", CustomerId = "1" },
new() { OrderId = $"{customerId}-98", CustomerId = "2" }
};
}
My query works fine for the top level but doesn't seem to filter the nested types.
query {
customers(where: { customerId: { eq: "1" } }) {
forename
lastName
orders {
orderId
}
}
}
I am clearly missing something or perhaps I misusing.
For my desired output I would need to change the query to be:
query {
customers(where: { customerId: { eq: "1" } }) {
forename
lastName
orders(where: { customerId: { eq: "1" } }) {
orderId
customerId
}
}
}