diff --git a/README.md b/README.md index 68f2dcf..0145b41 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,11 @@ query { IDs that are internally represented with `Integer`s, `Guid`s, `Long`s, `String`s. You can opt-out to each as required. -For integer-based or long-based IDs, you can pass `"1"` or `1` and both will be accepted. +For integer-based IDs, you can pass `"1"` or `1` and both will be accepted. -For all other types, you need to pass the string value, e.g. `"26a2dc8f-4dab-408c-88c6-523a0a89a2b5"` for a guid-based ID. +For all other types, you need to pass the string value, e.g. +* `"26a2dc8f-4dab-408c-88c6-523a0a89a2b5"` for a guid-based ID +* `"123456789"` for a long-based ID ### Any downsides? diff --git a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.Id_On_Arguments.verified.txt b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.Id_On_Arguments.verified.txt index d42845f..e1da1f5 100644 --- a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.Id_On_Arguments.verified.txt +++ b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.Id_On_Arguments.verified.txt @@ -4,6 +4,10 @@ "nullableIntId": "1", "nullableIntIdGivenNull": "null", "intIdList": "1", + "longId": "9223372036854775807", + "nullableLongId": "9223372036854775807", + "nullableLongIdGivenNull": "null", + "longIdList": "9223372036854775807", "stringId": "abc", "nullableStringId": "abc", "nullableStringIdGivenNull": "null", diff --git a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=False.verified.txt b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=False.verified.txt index 27c0536..5c208d9 100644 --- a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=False.verified.txt +++ b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=False.verified.txt @@ -18,6 +18,15 @@ { "message": "The ID \u0060abc\u0060 has an invalid format." }, + { + "message": "The IDs \u00609223372036854775807\u0060 have an invalid format." + }, + { + "message": "The ID \u00609223372036854775807\u0060 has an invalid format." + }, + { + "message": "The ID \u00609223372036854775807\u0060 has an invalid format." + }, { "message": "The IDs \u00601\u0060 have an invalid format." }, diff --git a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=True.verified.txt b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=True.verified.txt index d42845f..e1da1f5 100644 --- a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=True.verified.txt +++ b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.PolyId_On_Arguments_isEnabled=True.verified.txt @@ -4,6 +4,10 @@ "nullableIntId": "1", "nullableIntIdGivenNull": "null", "intIdList": "1", + "longId": "9223372036854775807", + "nullableLongId": "9223372036854775807", + "nullableLongIdGivenNull": "null", + "longIdList": "9223372036854775807", "stringId": "abc", "nullableStringId": "abc", "nullableStringIdGivenNull": "null", diff --git a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.cs b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.cs index c41f104..9c5b7e6 100644 --- a/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.cs +++ b/src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.cs @@ -27,6 +27,39 @@ public class IdAttributeTests // TODO: When PR 3440 in HC is merged, uncomment array with nulls field usages below in queries + private const string _argumentsQuery = @" + query foo ( + $intId: ID! + $longId: ID! + $stringId: ID! + $guidId: ID! + $null: ID = null) + { + intId(id: $intId) + nullableIntId(id: $intId) + nullableIntIdGivenNull: nullableIntId(id: $null) + intIdList(id: [$intId]) + # TODO: nullableIntIdList(id: [$intId, $null]) + + longId(id: $longId) + nullableLongId(id: $longId) + nullableLongIdGivenNull: nullableLongId(id: $null) + longIdList(id: [$longId]) + # TODO: nullableLongIdList(id: [$longId, $null]) + + stringId(id: $stringId) + nullableStringId(id: $stringId) + nullableStringIdGivenNull: nullableStringId(id: $null) + stringIdList(id: [$stringId]) + # TODO: nullableStringIdList(id: [$stringId, $null]) + + guidId(id: $guidId) + nullableGuidId(id: $guidId) + nullableGuidIdGivenNull: nullableGuidId(id: $null) + guidIdList(id: [$guidId $guidId]) + # TODO: nullableGuidIdList(id: [$guidId $null $guidId]) + }"; + [Theory] [InlineData(false)] [InlineData(true)] @@ -34,6 +67,7 @@ public async Task PolyId_On_Arguments(bool isEnabled) { // arrange var intId = 1; + var longId = long.MaxValue; var stringId = "abc"; var guidId = new Guid("26a2dc8f-4dab-408c-88c6-523a0a89a2b5"); var services = new ServiceCollection(); @@ -60,32 +94,9 @@ public async Task PolyId_On_Arguments(bool isEnabled) var result = await executor .ExecuteAsync( QueryRequestBuilder.New() - .SetQuery( - @"query foo ( - $intId: ID! - $nullIntId: ID = null - $stringId: ID! - $nullStringId: ID = null - $guidId: ID! - $nullGuidId: ID = null) - { - intId(id: $intId) - nullableIntId(id: $intId) - nullableIntIdGivenNull: nullableIntId(id: $nullIntId) - intIdList(id: [$intId]) - # TODO: nullableIntIdList(id: [$intId, $nullIntId]) - stringId(id: $stringId) - nullableStringId(id: $stringId) - nullableStringIdGivenNull: nullableStringId(id: $nullStringId) - stringIdList(id: [$stringId]) - # TODO: nullableStringIdList(id: [$stringId, $nullStringId]) - guidId(id: $guidId) - nullableGuidId(id: $guidId) - nullableGuidIdGivenNull: nullableGuidId(id: $nullGuidId) - guidIdList(id: [$guidId $guidId]) - # TODO: nullableGuidIdList(id: [$guidId $nullGuidId $guidId]) - }") + .SetQuery(_argumentsQuery) .SetVariableValue("intId", intId) + .SetVariableValue("longId", longId.ToString()) .SetVariableValue("stringId", stringId) .SetVariableValue("guidId", guidId.ToString()) .Create()); @@ -225,6 +236,7 @@ public async Task Id_On_Arguments() // arrange var idSerializer = new IdSerializer(); var intId = idSerializer.Serialize("Query", 1); + var longId = idSerializer.Serialize("Query", long.MaxValue); var stringId = idSerializer.Serialize("Query", "abc"); var guidId = idSerializer.Serialize("Query", new Guid("26a2dc8f-4dab-408c-88c6-523a0a89a2b5")); @@ -237,32 +249,9 @@ await SchemaBuilder.New() .MakeExecutable() .ExecuteAsync( QueryRequestBuilder.New() - .SetQuery( - @"query foo ( - $intId: ID! - $nullIntId: ID = null - $stringId: ID! - $nullStringId: ID = null - $guidId: ID! - $nullGuidId: ID = null) - { - intId(id: $intId) - nullableIntId(id: $intId) - nullableIntIdGivenNull: nullableIntId(id: $nullIntId) - intIdList(id: [$intId]) - # TODO: nullableIntIdList(id: [$intId, $nullIntId]) - stringId(id: $stringId) - nullableStringId(id: $stringId) - nullableStringIdGivenNull: nullableStringId(id: $nullStringId) - stringIdList(id: [$stringId]) - # TODO: nullableStringIdList(id: [$stringId, $nullStringId]) - guidId(id: $guidId) - nullableGuidId(id: $guidId) - nullableGuidIdGivenNull: nullableGuidId(id: $nullGuidId) - guidIdList(id: [$guidId $guidId]) - # TODO: nullableGuidIdList(id: [$guidId $nullGuidId $guidId]) - }") + .SetQuery(_argumentsQuery) .SetVariableValue("intId", intId) + .SetVariableValue("longId", longId.ToString()) .SetVariableValue("stringId", stringId) .SetVariableValue("guidId", guidId) .Create()); @@ -450,6 +439,14 @@ public string IntIdList([ID] int[] id) => public string NullableIntIdList([ID] int?[] id) => string.Join(", ", id.Select(t => t?.ToString() ?? "null")); + public string LongId([ID] long id) => id.ToString(); + public string LongIdList([ID] long[] id) => + string.Join(", ", id.Select(t => t.ToString())); + + public string NullableLongId([ID] long? id) => id?.ToString() ?? "null"; + public string NullableLongIdList([ID] long?[] id) => + string.Join(", ", id.Select(t => t?.ToString() ?? "null")); + public string StringId([ID] string id) => id; public string StringIdList([ID] string[] id) => string.Join(", ", id.Select(t => t.ToString())); diff --git a/src/AutoGuru.HotChocolate.PolymorphicIds/PolymorphicIdInputValueFormatter.cs b/src/AutoGuru.HotChocolate.PolymorphicIds/PolymorphicIdInputValueFormatter.cs index 26d252e..cf6e7d6 100644 --- a/src/AutoGuru.HotChocolate.PolymorphicIds/PolymorphicIdInputValueFormatter.cs +++ b/src/AutoGuru.HotChocolate.PolymorphicIds/PolymorphicIdInputValueFormatter.cs @@ -72,11 +72,6 @@ public PolymorphicIdInputValueFormatter( private IdValue DeserializeId(string value) { - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } - if ((_idRuntimeType == typeof(int) || _idRuntimeType == typeof(int?)) && value is string rawIntString && int.TryParse(rawIntString, out var intValue))