Skip to content

Commit

Permalink
Merge pull request #4 from autoguru-au/develop
Browse files Browse the repository at this point in the history
Support for [ID]! and [ID]
  • Loading branch information
benmccallum authored Jan 14, 2022
2 parents e779380 + dc42942 commit e24b017
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
"nullableIntId": "1",
"nullableIntIdGivenNull": "null",
"intIdList": "1",
"nullableIntIdList": "1, null",
"longId": "9223372036854775807",
"nullableLongId": "9223372036854775807",
"nullableLongIdGivenNull": "null",
"longIdList": "9223372036854775807",
"nullableLongIdList": "9223372036854775807, null",
"stringId": "abc",
"nullableStringId": "abc",
"nullableStringIdGivenNull": "null",
"stringIdList": "abc",
"nullableStringIdList": "abc, null",
"guidId": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidId": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidIdGivenNull": "null",
"guidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5"
"guidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, null, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"QmFyCmkx"
],
"someNullableIds": [
"QmFyCmkx"
"QmFyCmkx",
null
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{
"message": "The IDs \u00601\u0060 have an invalid format."
},
{
"message": "The IDs \u00601, \u0060 have an invalid format."
},
{
"message": "The ID \u00609223372036854775807\u0060 has an invalid format."
},
Expand All @@ -18,6 +21,9 @@
{
"message": "The IDs \u00609223372036854775807\u0060 have an invalid format."
},
{
"message": "The IDs \u00609223372036854775807, \u0060 have an invalid format."
},
{
"message": "The ID \u0060abc\u0060 has an invalid format."
},
Expand All @@ -27,6 +33,9 @@
{
"message": "The IDs \u0060abc\u0060 have an invalid format."
},
{
"message": "The IDs \u0060abc, \u0060 have an invalid format."
},
{
"message": "The ID \u006026a2dc8f-4dab-408c-88c6-523a0a89a2b5\u0060 has an invalid format."
},
Expand All @@ -35,6 +44,9 @@
},
{
"message": "The IDs \u006026a2dc8f-4dab-408c-88c6-523a0a89a2b5, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5\u0060 have an invalid format."
},
{
"message": "The IDs \u006026a2dc8f-4dab-408c-88c6-523a0a89a2b5, , 26a2dc8f-4dab-408c-88c6-523a0a89a2b5\u0060 have an invalid format."
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
"nullableIntId": "1",
"nullableIntIdGivenNull": "null",
"intIdList": "1",
"nullableIntIdList": "1, null",
"longId": "9223372036854775807",
"nullableLongId": "9223372036854775807",
"nullableLongIdGivenNull": "null",
"longIdList": "9223372036854775807",
"nullableLongIdList": "9223372036854775807, null",
"stringId": "abc",
"nullableStringId": "abc",
"nullableStringIdGivenNull": "null",
"stringIdList": "abc",
"nullableStringIdList": "abc, null",
"guidId": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidId": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidIdGivenNull": "null",
"guidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5"
"guidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5",
"nullableGuidIdList": "26a2dc8f-4dab-408c-88c6-523a0a89a2b5, null, 26a2dc8f-4dab-408c-88c6-523a0a89a2b5"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"data": {
"foo": {
"someId": "QmFyCmQx",
Expand All @@ -7,9 +7,10 @@
"QmFyCmkx"
],
"someNullableIds": [
"QmFyCmkx"
"QmFyCmkx",
null
],
"raw": "SomeId: 1, SomeIds: [1], SomeNullableId: 1, SomeNullableIds: [1]"
"raw": "SomeId: 1, SomeIds: [1], SomeNullableId: 1, SomeNullableIds: [1, null]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
schema {
query: Query
}

interface IFooPayload {
someId: ID!
someNullableId: ID
someIds: [ID!]!
someNullableIds: [ID]
raw: String!
}

type FooPayload implements IFooPayload {
someId: ID!
someIds: [ID!]!
someNullableId: ID
someNullableIds: [ID]
raw: String!
}

type Query {
intId(id: ID!): String!
intIdList(id: [ID!]!): String!
nullableIntId(id: ID): String!
nullableIntIdList(id: [ID]!): String!
longId(id: ID!): String!
longIdList(id: [ID!]!): String!
nullableLongId(id: ID): String!
nullableLongIdList(id: [ID]!): String!
stringId(id: ID!): String!
stringIdList(id: [ID!]!): String!
nullableStringId(id: ID): String!
nullableStringIdList(id: [ID]!): String!
guidId(id: ID!): String!
guidIdList(id: [ID!]!): String!
nullableGuidId(id: ID): String!
nullableGuidIdList(id: [ID]!): String!
foo(input: FooInput!): IFooPayload!
lol(input: LolInput!): Int!
}

input FooInput {
someId: ID!
someNullableId: ID
someIds: [ID!]!
someNullableIds: [ID]
}

input LolInput {
someId: Int!
}

"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`."
directive @defer("If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to." label: String "Deferred when true." if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT

"The `@stream` directive may be provided for a field of `List` type so that the backend can leverage technology such as asynchronous iterators to provide a partial list in the initial response, and additional list items in subsequent responses. `@include` and `@skip` take precedence over `@stream`."
directive @stream("If this argument label has a value other than null, it will be passed on to the result of this stream directive. This label is intended to give client applications a way to identify to which fragment a streamed result belongs to." label: String "The initial elements that shall be send down to the consumer." initialCount: Int! "Streamed when true." if: Boolean) on FIELD
41 changes: 29 additions & 12 deletions src/AutoGuru.HotChocolate.PolymorphicIds.Tests/IdAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace AutoGuru.HotChocolate.PolymorphicIds.Tests
{
[UsesVerify]
[SuppressMessage("Style", "IDE1006:Naming Styles")]
[SuppressMessage("Performance", "CA1822:Mark members as static")]
public class IdAttributeTests
{
private static readonly RequestExecutorOptions _executorOptions = new ()
Expand All @@ -26,8 +25,6 @@ public class IdAttributeTests
IncludeExceptionDetails = true
};

// 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!
Expand All @@ -40,25 +37,25 @@ query foo (
nullableIntId(id: $intId)
nullableIntIdGivenNull: nullableIntId(id: $null)
intIdList(id: [$intId])
# TODO: nullableIntIdList(id: [$intId, $null])
nullableIntIdList(id: [$intId, $null])
longId(id: $longId)
nullableLongId(id: $longId)
nullableLongIdGivenNull: nullableLongId(id: $null)
longIdList(id: [$longId])
# TODO: nullableLongIdList(id: [$longId, $null])
nullableLongIdList(id: [$longId, $null])
stringId(id: $stringId)
nullableStringId(id: $stringId)
nullableStringIdGivenNull: nullableStringId(id: $null)
stringIdList(id: [$stringId])
# TODO: nullableStringIdList(id: [$stringId, $null])
nullableStringIdList(id: [$stringId, $null])
guidId(id: $guidId)
nullableGuidId(id: $guidId)
nullableGuidIdGivenNull: nullableGuidId(id: $null)
guidIdList(id: [$guidId $guidId])
# TODO: nullableGuidIdList(id: [$guidId $null $guidId])
nullableGuidIdList(id: [$guidId $null $guidId])
}";

[Theory]
Expand Down Expand Up @@ -167,7 +164,8 @@ await SchemaBuilder.New()
someId: $someId
someIds: [$someIntId]
someNullableId: $someId
someNullableIds: [$someIntId] }) # TODO: null] })
someNullableIds: [$someIntId, null]
})
{
someId
someNullableId
Expand Down Expand Up @@ -320,7 +318,8 @@ await SchemaBuilder.New()
someId: $someId
someIds: [$someIntId]
someNullableId: $someId
someNullableIds: [$someIntId] })
someNullableIds: [$someIntId]
})
{
someId
someNullableId
Expand Down Expand Up @@ -368,7 +367,8 @@ await SchemaBuilder.New()
someId: $someId
someIds: [$someIntId]
someNullableId: null
someNullableIds: [$someIntId] }) # TODO: null
someNullableIds: [$someIntId, null]
})
{
someId
someNullableId
Expand Down Expand Up @@ -466,6 +466,23 @@ await Verifier.Verify(new

#endregion

[Fact]
public async Task Schema()
{
// arrange / act
var schema =
SchemaBuilder.New()
.AddQueryType<Query>()
.AddType<FooPayload>()
.AddPolymorphicIds()
.Create()
.ToString();

// assert
await Verifier.Verify(schema);
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Can't be static for HC")]
public class Query
{
public string IntId([ID] int id) => id.ToString();
Expand Down Expand Up @@ -554,8 +571,8 @@ public FooPayload(
public string Raw =>
$"{nameof(SomeId)}: {SomeId}, " +
$"{nameof(SomeIds)}: [{string.Join(", ", SomeIds)}], " +
$"{nameof(SomeNullableId)}: {SomeNullableId}, " +
$"{nameof(SomeNullableIds)}: [{string.Join(", ", SomeNullableIds ?? Array.Empty<int?>())}]";
$"{nameof(SomeNullableId)}: {SomeNullableId ?? "null"}, " +
$"{nameof(SomeNullableIds)}: {(SomeNullableIds == null ? "null" : "[" + string.Join(", ", SomeNullableIds.Select(x => x?.ToString() ?? "null").ToArray()) + "]")}";
}

public interface IFooPayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ public PolymorphicIdInputValueFormatter(
return DeserializeId(s);
}

if (runtimeValue is IEnumerable<string> stringEnumerable) // TODO: When PR 3440 in HC is merged, this should become IEnumerable<string?>
if (runtimeValue is IEnumerable<string?> stringEnumerable)
{
try
{
var list = new List<IdValue>();// TODO: When PR 3440 in HC is merged, this should become List<IdValue?>
var list = new List<IdValue?>();
foreach (var sv in stringEnumerable)
{
// TODO: When PR 3440 in HC is merged, this should be uncommented
//if (sv is null)
//{
// list.Add(null);
//}
//else
//{
list.Add(DeserializeId(sv));
//}
if (sv is null)
{
list.Add(null);
}
else
{
list.Add(DeserializeId(sv));
}
}
return list;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Product>Polymorphic IDs.</Product>
<Description>Polymorphic Relay IDs for HotChocolate</Description>
<PackageTags>GraphQL HotChocolate Relay</PackageTags>
<Version>2.0.0</Version>
<Version>2.1.0</Version>

<PackageProjectUrl>https://github.com/autoguru-au/hotchocolate-polymorphic-ids</PackageProjectUrl>
<RepositoryUrl>https://github.com/autoguru-au/hotchocolate-polymorphic-ids</RepositoryUrl>
Expand All @@ -21,7 +21,6 @@

<TargetFrameworks>net5.0; netcoreapp3.1; netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildProjectName.EndsWith('Tests'))">net5.0; netcoreapp3.1</TargetFrameworks>

</PropertyGroup>

</Project>

0 comments on commit e24b017

Please sign in to comment.