Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object field resolver respects inheritance #2515

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ protected ResolverCompiler()
protected ParameterExpression Context { get; }

protected static MethodInfo Parent { get; } =
typeof(IResolverContext).GetMethod(nameof(Parent))!;
typeof(IResolverContext).GetMethod(nameof(IResolverContext.Parent))!;

protected static MethodInfo Resolver { get; } =
typeof(IResolverContext).GetMethod(nameof(Resolver))!;
typeof(IResolverContext).GetMethod(nameof(IResolverContext.Resolver))!;

protected IEnumerable<Expression> CreateParameters(
IEnumerable<ParameterInfo> parameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public IObjectFieldDescriptor Field(NameString name)
Context,
propertyOrMethod,
Definition.RuntimeType,
propertyOrMethod.DeclaringType ?? Definition.RuntimeType);
propertyOrMethod.ReflectedType ?? Definition.RuntimeType);
Fields.Add(fieldDescriptor);
return fieldDescriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ public async Task Node_Resolve_Separated_Resolver()
result.ToJson().MatchSnapshot();
}

[Fact]
public async Task Node_Resolve_Parent_Id()
{
// arrange
ISchema schema = SchemaBuilder.New()
.EnableRelaySupport()
.AddQueryType(
x => x.Name("Query")
.Field("childs")
.Resolve(new Child { Id = "123" }))
.AddObjectType<Child>(d => d
.ImplementsNode()
.IdField(t => t.Id)
.ResolveNode((ctx, id) => Task.FromResult(new Child { Id = id })))
.Create();

IRequestExecutor executor = schema.MakeExecutable();

// act
IExecutionResult result = await executor.ExecuteAsync("{ childs { id } }");

// assert
result.ToJson().MatchSnapshot();
}

[Fact]
public async Task Node_Resolve_Separated_Resolver_ImplicitId()
{
Expand Down Expand Up @@ -265,5 +290,14 @@ public class Bar4

public static Bar2 GetFoo(string id) => new Bar2 { Id = id };
}

public class Parent
{
public string Id { get; set; }
}

public class Child : Parent
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"data": {
"childs": {
"id": "Q2hpbGQKZDEyMw=="
}
}
}