-
-
Notifications
You must be signed in to change notification settings - Fork 803
Expand file tree
/
Copy pathTrueNullabilityTests.cs
More file actions
174 lines (154 loc) · 4.96 KB
/
TrueNullabilityTests.cs
File metadata and controls
174 lines (154 loc) · 4.96 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#nullable enable
using CookieCrumble;
using Microsoft.Extensions.DependencyInjection;
namespace HotChocolate.Execution;
public class TrueNullabilityTests
{
[Fact]
public async Task Schema_Without_TrueNullability()
{
var schema =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = false)
.BuildSchemaAsync();
schema.MatchSnapshot();
}
[Fact]
public async Task Schema_With_TrueNullability()
{
var schema =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.BuildSchemaAsync();
schema.MatchSnapshot();
}
[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Enabled_By_Default()
{
var response =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.ExecuteRequestAsync(
"""
query {
book {
name
author {
name
}
}
}
""");
response.MatchSnapshot();
}
[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Enabled()
{
var response =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.ExecuteRequestAsync(
"""
query @nullBubbling {
book {
name
author {
name
}
}
}
""");
response.MatchSnapshot();
}
[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Disabled()
{
var response =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.ExecuteRequestAsync(
"""
query @nullBubbling(enable: false) {
book {
name
author {
name
}
}
}
""");
response.MatchSnapshot();
}
[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Disabled_With_Variable()
{
var response =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.ExecuteRequestAsync(
QueryRequestBuilder.New()
.SetQuery(
"""
query($enable: Boolean!) @nullBubbling(enable: $enable) {
book {
name
author {
name
}
}
}
""")
.SetVariableValue("enable", false)
.Create());
response.MatchSnapshot();
}
[Fact]
public async Task Error_Query_With_NullBubbling_Disabled()
{
var request = QueryRequestBuilder.New()
.SetQuery("""
query {
book {
name
author {
name
}
}
}
""")
.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true)
.Create();
var response =
await new ServiceCollection()
.AddGraphQLServer()
.ModifyRequestOptions(options => options.AllowDisablingNullBubbling = true)
.AddQueryType<Query>()
.ExecuteRequestAsync(request);
response.MatchSnapshot();
}
public class Query
{
public Book? GetBook() => new();
}
public class Book
{
public string Name => "Some book!";
public Author Author => new();
}
public class Author
{
public string Name => throw new Exception();
}
}