Skip to content

Commit

Permalink
Fixed Argument Parser (#6596)
Browse files Browse the repository at this point in the history
  • Loading branch information
darren-clark authored Oct 12, 2023
1 parent 0a2967e commit 183638f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private static bool TryGetValue<T>(
int i,
out T? value)
{
type = type is NonNullType nonNullType ? nonNullType.Type : type;
switch (valueNode.Kind)
{
case SyntaxKind.ObjectValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,66 @@ public async void TestResolveViaEntityResolver_NoResolverFound()
await Assert.ThrowsAsync<SchemaException>(ShouldThrow);
}

[Fact]
public async Task TestDetailFieldResolver_Required()
{
var schema = SchemaBuilder.New()
.AddApolloFederation()
.AddQueryType<Query>()
.AddType<FederatedTypeWithRequiredDetail>()
.Create();

var context = CreateResolverContext(schema);

var representations = new List<Representation>
{
new("FederatedTypeWithRequiredDetail",
new ObjectValueNode(new[]
{
new ObjectFieldNode("detail",
new ObjectValueNode(new[] { new ObjectFieldNode("id", "testId") }))
}))
};

var result = await EntitiesResolver.ResolveAsync(schema, representations, context);

Assert.Equal(1, result.Count);
var obj = Assert.IsType<FederatedTypeWithRequiredDetail>(result[0]);

Assert.Equal("testId", obj.Id);
Assert.Equal("testId", obj.Detail.Id);
}

[Fact]
public async Task TestDetailFieldResolver_Optional()
{
var schema = SchemaBuilder.New()
.AddApolloFederation()
.AddQueryType<Query>()
.AddType<FederatedTypeWithOptionalDetail>()
.Create();

var context = CreateResolverContext(schema);

var representations = new List<Representation>
{
new("FederatedTypeWithOptionalDetail",
new ObjectValueNode(new[]
{
new ObjectFieldNode("detail",
new ObjectValueNode(new[] { new ObjectFieldNode("id", "testId") }))
}))
};

var result = await EntitiesResolver.ResolveAsync(schema, representations, context);

Assert.Equal(1, result.Count);
var obj = Assert.IsType<FederatedTypeWithOptionalDetail>(result[0]);

Assert.Equal("testId", obj.Id);
Assert.Equal("testId", obj.Detail!.Id);
}

public class Query
{
public ForeignType ForeignType { get; set; } = default!;
Expand Down Expand Up @@ -291,4 +351,30 @@ protected override Task<IReadOnlyDictionary<string, FederatedType>> LoadBatchAsy
return Task.FromResult<IReadOnlyDictionary<string, FederatedType>>(result);
}
}

public class FederatedTypeWithRequiredDetail
{
public string Id { get; set; } = default!;

public FederatedTypeDetail Detail { get; set; } = default!;

[ReferenceResolver]
public static FederatedTypeWithRequiredDetail ReferenceResolver([Map("detail.id")] string detailId) => new() { Id = detailId, Detail = new FederatedTypeDetail { Id = detailId } };
}

public class FederatedTypeWithOptionalDetail
{
public string Id { get; set; } = default!;

public FederatedTypeDetail? Detail { get; set; } = default!;

[ReferenceResolver]
public static FederatedTypeWithOptionalDetail ReferenceResolver([Map("detail.id")] string detailId) => new() { Id = detailId, Detail = new FederatedTypeDetail { Id = detailId } };

}

public class FederatedTypeDetail
{
public string Id { get; set; } = default!;
}
}

0 comments on commit 183638f

Please sign in to comment.