Skip to content

Commit 8abf12b

Browse files
authored
[Fusion] Added support for shorthand SelectedObjectField in validator (#8236)
1 parent 86773a7 commit 8abf12b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Utilities/Validators/FieldSelectionMapValidator.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,23 @@ protected override ISyntaxVisitorAction Enter(
286286
context.InputTypes.Push(currentInputType);
287287
}
288288

289+
if (node.SelectedValue is null
290+
&& context.OutputTypes.Peek() is MutableComplexTypeDefinition complexType)
291+
{
292+
if (!complexType.Fields.TryGetField(node.Name.Value, out var field))
293+
{
294+
context.Errors.Add(
295+
string.Format(
296+
FieldSelectionMapValidator_FieldDoesNotExistOnType,
297+
node.Name,
298+
complexType.Name));
299+
300+
return Skip;
301+
}
302+
303+
context.SelectedFields.Add(field);
304+
}
305+
289306
return Continue;
290307
}
291308

src/HotChocolate/Fusion-vnext/test/Fusion.Utilities.Tests/Validators/FieldSelectionMapValidatorTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public static TheoryData<string, string, string> ValidExamplesData()
268268
{ "FindMediaInput", "Media", "{ bookId: <Book>.id } | { movieId: <Movie>.id }" },
269269
{ "Nested", "Media", "{ nested: { bookId: <Book>.id } | { movieId: <Movie>.id } }" },
270270
// Other tests.
271+
{ "String", "Book", "{ id title }" },
271272
{ "ID", "Query", "mediaById<Book>.author.id | mediaById<Movie>.id" },
272273
{ "ID", "Media", "{ bookId: <Book>.author.id } | { movieId: <Movie>.id }" }
273274
};
@@ -319,6 +320,15 @@ public static TheoryData<string, string, string, string[]> InvalidExamplesData()
319320
// TODO: 6.3.6 Selected Object Field Uniqueness examples.
320321
// Blocked by https://github.com/graphql/composite-schemas-spec/issues/171.
321322
// Additional tests.
323+
{
324+
"String",
325+
"Book",
326+
"{ id unknownField1 unknownField2 }",
327+
[
328+
"The field 'unknownField1' does not exist on the type 'Book'.",
329+
"The field 'unknownField2' does not exist on the type 'Book'."
330+
]
331+
},
322332
{
323333
"ID",
324334
"Media",

0 commit comments

Comments
 (0)