-
-
Notifications
You must be signed in to change notification settings - Fork 804
Expand file tree
/
Copy pathIssue6953Tests.cs
More file actions
116 lines (100 loc) · 2.97 KB
/
Issue6953Tests.cs
File metadata and controls
116 lines (100 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using HotChocolate.Execution;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
namespace HotChocolate.Data;
public class Issue6953Tests
{
[Fact]
public async Task UseProjection_On_List_Union_With_Fragments_Does_Not_Throw()
{
var executor = await CreateExecutorAsync();
var result = await executor.ExecuteAsync(
"""
{
unionTest {
__typename
... on ChildA {
a
}
... on ChildB {
b
}
}
}
""");
var operationResult = result.ExpectOperationResult();
Assert.Empty(operationResult.Errors ?? []);
}
[Fact]
public async Task UseProjection_On_List_Union_With_Typename_Only_Does_Not_Throw()
{
var executor = await CreateExecutorAsync();
var result = await executor.ExecuteAsync(
"""
{
unionTest {
__typename
}
}
""");
var operationResult = result.ExpectOperationResult();
Assert.Empty(operationResult.Errors ?? []);
}
private static ValueTask<IRequestExecutor> CreateExecutorAsync()
=> new ServiceCollection()
.AddGraphQL()
.AddProjections()
.AddQueryType<Query>()
.AddType<ChildAType>()
.AddType<ChildBType>()
.AddType<UnionTestType>()
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
.BuildRequestExecutorAsync();
public class Query
{
[UseProjection]
[GraphQLType(typeof(ListType<UnionTestType>))]
public IQueryable<Base> GetUnionTest()
=> Data.AsQueryable();
}
public class Base
{
public string C { get; set; } = string.Empty;
}
public class ChildA : Base
{
public string A { get; set; } = string.Empty;
}
public class ChildB : Base
{
public string B { get; set; } = string.Empty;
}
public class ChildAType : ObjectType<ChildA>
{
protected override void Configure(IObjectTypeDescriptor<ChildA> descriptor)
{
descriptor.Field(x => x.A).Type<NonNullType<StringType>>();
}
}
public class ChildBType : ObjectType<ChildB>
{
protected override void Configure(IObjectTypeDescriptor<ChildB> descriptor)
{
descriptor.Field(x => x.B).Type<NonNullType<StringType>>();
}
}
public class UnionTestType : UnionType
{
protected override void Configure(IUnionTypeDescriptor descriptor)
{
descriptor.Name("UnionTestType");
descriptor.Type<ChildAType>();
descriptor.Type<ChildBType>();
}
}
private static readonly Base[] Data =
[
new ChildA { C = "shared-a", A = "value-a" },
new ChildB { C = "shared-b", B = "value-b" }
];
}