Skip to content

Commit

Permalink
fix property ignores from base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
floyd-may committed Jan 18, 2021
1 parent a327cb8 commit 026f2b5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
52 changes: 50 additions & 2 deletions OttoTheGeek.Tests/ScalarObjectQueryResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ protected override SchemaBuilder ConfigureSchema(SchemaBuilder builder)
return builder.GraphType<SimpleScalarQueryModel<ChildObject>>(b =>
b.Named("Query").LooseScalarField(x => x.Child)
.ResolvesVia<ChildResolver>()
);
).GraphType<ChildObject>(BuildChildObject);
}

private GraphTypeBuilder<ChildObject> BuildChildObject(GraphTypeBuilder<ChildObject> builder)
{
return builder.IgnoreProperty(x => x.Ignored);
}
}

Expand All @@ -34,7 +39,11 @@ public Task<ChildObject> Resolve()
}
}

public sealed class ChildObject
public class ChildObjectBase
{
public int Ignored { get; set; }
}
public sealed class ChildObject : ChildObjectBase
{
public string Value1 => "hello";
public string Value2 => "world";
Expand Down Expand Up @@ -82,6 +91,45 @@ public void BuildsSchemaType()
queryType.Should().BeEquivalentTo(expectedType);
}

[Fact]
public void BuildsChildObjectType()
{
var server = new WorkingModel().CreateServer();

var rawResult = server.Execute<JObject>(@"{
__type(name:""ChildObject"") {
name
kind
fields {
name
}
}
}");

var expectedType = new ObjectType {
Kind = ObjectKinds.Object,
Name = "ChildObject",
Fields = new [] {
new ObjectField
{
Name = "value1"
},
new ObjectField
{
Name = "value2"
},
new ObjectField
{
Name = "value3"
},
}
};

var queryType = rawResult["__type"].ToObject<ObjectType>();

queryType.Should().BeEquivalentTo(expectedType);
}

[Fact]
public void ReturnsObjectValues()
{
Expand Down
2 changes: 1 addition & 1 deletion OttoTheGeek/GraphTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public ComplexGraphType<TModel> BuildGraphType (GraphTypeCache cache, IServiceCo
return cache.GetOrCreate<TModel> (services);
}

foreach (var prop in typeof (TModel).GetProperties ().Except (_config.PropsToIgnore)) {
foreach (var prop in typeof (TModel).GetProperties ().Where(x => !_config.IsPropertyIgnored(x))) {
var fieldConfig = _config.GetFieldConfig(prop);
fieldConfig.ConfigureField(graphType, cache, services);
}
Expand Down
6 changes: 6 additions & 0 deletions OttoTheGeek/Internal/GraphTypeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public GraphTypeConfiguration<T> ConfigureField(PropertyInfo prop, Func<FieldCon
return Clone(fieldConfig: _fieldConfig.Add(prop, newConfig));
}

public bool IsPropertyIgnored(PropertyInfo prop)
{
return PropsToIgnore
.Any(x => x.DeclaringType == prop.DeclaringType && x.Name == prop.Name);
}

public FieldConfiguration<T> GetFieldConfig(PropertyInfo prop)
{
return _fieldConfig.Get(prop)
Expand Down
3 changes: 0 additions & 3 deletions OttoTheGeek/Internal/ListFieldBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;

namespace OttoTheGeek.Internal
Expand Down

0 comments on commit 026f2b5

Please sign in to comment.