Skip to content

Commit 4b27509

Browse files
committed
(WIP) Moved validation from OneOf-specific rule to VariablesInAllowedPositions
1 parent 16a39a8 commit 4b27509

24 files changed

+158
-259
lines changed

dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ BCPROCKS
1818
bfnrt
1919
blazor
2020
blazorwasm
21+
Brontie
2122
Browsable
2223
BSON
2324
buildtransitive

src/HotChocolate/Core/src/Validation/ErrorHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ public static IError OneOfMustHaveExactlyOneField(
649649
.AddLocation(node)
650650
.SetPath(context.CreateErrorPath())
651651
.SetExtension(nameof(type), type.Name)
652-
.SpecifiedBy("sec-OneOf-Input-Objects-Have-Exactly-One-Field", rfc: 825)
652+
.SpecifiedBy("sec-All-Variable-Usages-Are-Allowed", rfc: 825)
653653
.Build();
654654

655655
public static IError OneOfVariablesMustBeNonNull(
@@ -666,7 +666,7 @@ public static IError OneOfVariablesMustBeNonNull(
666666
.AddLocation(node)
667667
.SetPath(context.CreateErrorPath())
668668
.SetFieldCoordinate(fieldCoordinate)
669-
.SpecifiedBy("sec-OneOf–Input-Objects-Have-Exactly-One-Field", rfc: 825)
669+
.SpecifiedBy("sec-All-Variable-Usages-Are-Allowed", rfc: 825)
670670
.Build();
671671

672672
public static IError SkipAndIncludeNotAllowedOnSubscriptionRootField(

src/HotChocolate/Core/src/Validation/Rules/VariableVisitor.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private bool IsVariableUsageAllowed(
284284
IType locationType,
285285
IValueNode? locationDefault)
286286
{
287-
if (locationType.IsNonNullType()
287+
if (IsNonNullPosition(locationType, variableDefinition)
288288
&& !variableDefinition.Type.IsNonNullType())
289289
{
290290
if (variableDefinition.DefaultValue.IsNull()
@@ -303,6 +303,20 @@ private bool IsVariableUsageAllowed(
303303
locationType);
304304
}
305305

306+
private static bool IsNonNullPosition(
307+
IType locationType,
308+
VariableDefinitionNode _)
309+
{
310+
if (locationType.IsNonNullType())
311+
{
312+
return true;
313+
}
314+
315+
// FIXME: How to implement this part?
316+
317+
return false;
318+
}
319+
306320
// http://facebook.github.io/graphql/June2018/#AreTypesCompatible()
307321
private bool AreTypesCompatible(
308322
ITypeNode variableType,

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_null_Error.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_null_and_B_is_null_Error.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_null_and_B_is_set_Error.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"errors": [
33
{
44
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_set_and_B_is_null_Error.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"errors": [
33
{
44
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_set_and_B_is_set_Error.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"errors": [
33
{
44
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_set_and_B_is_set_to_string_Error.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"errors": [
33
{
44
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
},

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_unset_variable_and_B_is_set_Error.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"extensions": {
1515
"type": "ExampleInput",
16-
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-All-Variable-Usages-Are-Allowed",
1717
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
1818
}
1919
}

0 commit comments

Comments
 (0)