Skip to content

Commit 432e8e0

Browse files
committed
Added failing test
1 parent 3caed1f commit 432e8e0

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

test/Linq2GraphQL.TestClient/Generated/Types/Customer.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
namespace Linq2GraphQL.TestClient;
1515

1616

17+
public static class CustomerExtensions
18+
{
19+
[GraphQLMember("relatedCustomers")]
20+
public static List<Customer> RelatedCustomers(this Customer customer, [GraphQLArgument("relationType", "Int!")] int relationType)
21+
{
22+
return customer.GetMethodValue<List<Customer>>("relatedCustomers", relationType);
23+
}
24+
25+
[GraphQLMember("relatedCustomer")]
26+
public static Customer RelatedCustomer(this Customer customer, [GraphQLArgument("relationType", "Int!")] int relationType)
27+
{
28+
return customer.GetMethodValue<Customer>("relatedCustomer", relationType);
29+
}
30+
31+
}
32+
1733
public partial class Customer : GraphQLTypeBase
1834
{
1935
[GraphQLMember("customerId")]
@@ -36,4 +52,16 @@ public partial class Customer : GraphQLTypeBase
3652
[JsonPropertyName("address")]
3753
public Address Address { get; set; }
3854

55+
private LazyProperty<List<Customer>> _relatedCustomers = new();
56+
/// <summary>
57+
/// Do not use in Query, only to retrive result
58+
/// </summary>
59+
public List<Customer> RelatedCustomers => _relatedCustomers.Value(() => GetFirstMethodValue<List<Customer>>("relatedCustomers"));
60+
61+
private LazyProperty<Customer> _relatedCustomer = new();
62+
/// <summary>
63+
/// Do not use in Query, only to retrive result
64+
/// </summary>
65+
public Customer RelatedCustomer => _relatedCustomer.Value(() => GetFirstMethodValue<Customer>("relatedCustomer"));
66+
3967
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Linq2GraphQL.TestServer.Data;
2+
using Linq2GraphQL.TestServer.Models;
3+
4+
namespace Linq2GraphQL.TestServer
5+
{
6+
[ExtendObjectType(typeof(Customer))]
7+
public class OrderGraphQLExtensions
8+
{
9+
public List<Customer> RelatedCustomers(int relationType)
10+
{
11+
return SampleData.GetCustomers();
12+
}
13+
14+
public Customer RelatedCustomer(int relationType)
15+
{
16+
return SampleData.GetCustomers().FirstOrDefault();
17+
}
18+
19+
}
20+
}

test/Linq2GraphQL.TestServer/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.AddQueryType<Query>()
88
.AddMutationType<Mutation>()
99
.AddSubscriptionType<Subscription>()
10+
.AddTypeExtension<OrderGraphQLExtensions>()
1011
.AddType<Pig>()
1112
.AddType<Spider>()
1213
.AddFiltering()

test/Linq2GraphQL.Tests/QueryIncludeTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ public async Task IncludePrimitives()
2525
Assert.Null(result.First().Address);
2626
}
2727

28+
[Fact]
29+
public async Task IncludeMethod_MultipleLevels()
30+
{
31+
var query = sampleClient
32+
.Query
33+
.Customers()
34+
.Include(e => e.Select(c => c.RelatedCustomer(2).Orders.Select(o => o.Address)))
35+
.Select();
36+
37+
var req = await query.GetRequestAsJsonAsync();
38+
var result = await query.ExecuteBaseAsync();
39+
40+
var customer = result.First();
41+
Assert.Equal(Guid.Empty, customer.CustomerId);
42+
43+
44+
}
45+
46+
2847

2948
[Fact]
3049
public async Task IncludePrimitives_MultipleLevels()

0 commit comments

Comments
 (0)