Skip to content

Commit 8d28538

Browse files
authored
Made the introspection capabilities check more robust. (#8957)
1 parent 32690e3 commit 8d28538

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

src/HotChocolate/Utilities/src/Utilities.Introspection/CapabilityInspector.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private async Task InspectArgumentDeprecationAsync()
7171

7272
if (result.Data.ValueKind is JsonValueKind.Object
7373
&& result.Data.TryGetProperty("__type", out var type)
74+
&& type.ValueKind is JsonValueKind.Object
7475
&& type.TryGetProperty("fields", out var fields))
7576
{
7677
foreach (var field in fields.EnumerateArray())
@@ -129,9 +130,18 @@ private async Task InspectDirectiveTypeAsync()
129130
using var response = await _client.SendAsync(request, _cancellationToken).ConfigureAwait(false);
130131
using var result = await response.ReadAsResultAsync(_cancellationToken).ConfigureAwait(false);
131132

132-
if (result.Data.ValueKind is JsonValueKind.Object
133-
&& result.Data.TryGetProperty("__type", out var type)
134-
&& type.TryGetProperty("fields", out var fields))
133+
if (result.Data.ValueKind is not JsonValueKind.Object
134+
|| !result.Data.TryGetProperty("__type", out var type)
135+
|| type.ValueKind is not JsonValueKind.Object
136+
|| !type.TryGetProperty("fields", out var fields))
137+
{
138+
// if we cannot detect features because __type does return null,
139+
// we will assume `locations` exists but assume all other
140+
// directive related features do not exist.
141+
_features.HasDirectiveLocations = true;
142+
_features.HasRepeatableDirectives = false;
143+
}
144+
else
135145
{
136146
var locations = false;
137147
var isRepeatable = false;
@@ -203,6 +213,7 @@ private async Task InspectDirectivesAsync()
203213

204214
if (result.Data.ValueKind is JsonValueKind.Object
205215
&& result.Data.TryGetProperty("__schema", out var schema)
216+
&& schema.ValueKind is JsonValueKind.Object
206217
&& schema.TryGetProperty("directives", out var directives))
207218
{
208219
var defer = false;
@@ -278,6 +289,7 @@ private async Task InspectSchemaAsync()
278289

279290
if (result.Data.ValueKind is JsonValueKind.Object
280291
&& result.Data.TryGetProperty("__type", out var type)
292+
&& type.ValueKind is JsonValueKind.Object
281293
&& type.TryGetProperty("fields", out var fields))
282294
{
283295
var description = false;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
query IntrospectionQuery {
2-
__type(name: "__Field") {
3-
fields {
4-
name
5-
args {
6-
name
7-
}
8-
}
2+
__type(name: "__Field") {
3+
fields {
4+
name
5+
args {
6+
name
7+
}
98
}
9+
}
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
query IntrospectionQuery {
2-
__schema {
3-
directives {
4-
name
5-
}
2+
__schema {
3+
directives {
4+
name
65
}
6+
}
77
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
query IntrospectionQuery {
2-
__type(name: "__Schema") {
3-
fields {
4-
name
5-
}
2+
__type(name: "__Schema") {
3+
fields {
4+
name
65
}
6+
}
77
}

0 commit comments

Comments
 (0)