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

V10 Adds Unignore #1458

Merged
merged 1 commit into from
Feb 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using HotChocolate.Execution;
Expand Down Expand Up @@ -102,6 +102,26 @@ public void IgnoreOverridenPropertyField()
t => Assert.Equal("c", t));
}

[Fact]
public void UnignoreOverridenPropertyField()
{
// arrange
var descriptor = new ObjectTypeDescriptor<Foo>(Context);

// act
descriptor.Field(t => t.B).Ignore();
descriptor.Field(t => t.B).Ignore(false);

// assert
Assert.Collection(
descriptor.CreateDefinition().Fields
.Select(t => t.Name)
.OrderBy(t => t),
t => Assert.Equal("a", t),
t => Assert.Equal("b", t),
t => Assert.Equal("c", t));
}


[Fact]
public void IgnoreOverridenMethodField()
Expand All @@ -123,6 +143,28 @@ public void IgnoreOverridenMethodField()
t => Assert.Equal("c", t));
}

[Fact]
public void UnignoreOverridenMethodField()
{
// arrange
var descriptor = new ObjectTypeDescriptor<Foo>(Context);

// act
IObjectTypeDescriptor<Foo> desc = descriptor;
desc.Field(t => t.Equals(default)).Ignore();
desc.Field(t => t.Equals(default)).Ignore(false);

// assert
Assert.Collection(
descriptor.CreateDefinition().Fields
.Select(t => t.Name)
.OrderBy(t => t),
t => Assert.Equal("a", t),
t => Assert.Equal("b", t),
t => Assert.Equal("c", t),
t => Assert.Equal("equals", t));
}

[Fact]
public void DeclareFieldsExplicitly()
{
Expand Down
37 changes: 37 additions & 0 deletions src/Core/Types.Tests/Types/InterfaceTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,43 @@ public void IgnoreFieldsFromClrInterface()
});
}

[Fact]
public void UnignoreFieldsFromClrInterface()
{
// arrange
// act
InterfaceType<IFoo> fooType = CreateType(
new InterfaceType<IFoo>(t =>
{
t.Ignore(p => p.Bar);
t.Field(p => p.Bar).Ignore(false);
}),
b => b.ModifyOptions(o => o.StrictValidation = false));

// assert
Assert.Collection(
fooType.Fields.Where(t => !t.IsIntrospectionField),
t =>
{
Assert.Equal("bar", t.Name);
Assert.IsType<BooleanType>(
Assert.IsType<NonNullType>(t.Type).Type);
},
t =>
{
Assert.Equal("baz", t.Name);
Assert.IsType<StringType>(t.Type);
},
t =>
{
Assert.Equal("qux", t.Name);
Assert.IsType<IntType>(
Assert.IsType<NonNullType>(t.Type).Type);
Assert.Collection(t.Arguments,
a => Assert.Equal("a", a.Name));
});
}

[Fact]
public void ExplicitInterfaceFieldDeclaration()
{
Expand Down
20 changes: 20 additions & 0 deletions src/Core/Types.Tests/Types/ObjectTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,26 @@ public void IgnoreFieldWithShortcut()

}

[Fact]
public void UnignoreFieldWithShortcut()
{
// arrange
// act
ObjectType<Foo> fooType = CreateType(new ObjectType<Foo>(d =>
{
d.Ignore(t => t.Description);
d.Field("foo").Type<StringType>().Resolver("abc");
d.Field(t => t.Description).Ignore(false);
}));

// assert
Assert.Collection(
fooType.Fields.Where(t => !t.IsIntrospectionField),
t => Assert.Equal("description", t.Name),
t => Assert.Equal("foo", t.Name));

}

[Fact]
public void IgnoreField_DescriptorIsNull_ArgumentNullException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reflection;
using HotChocolate.Execution;
using HotChocolate.Resolvers.CodeGeneration;
using HotChocolate.Subscriptions;

namespace HotChocolate.Resolvers.Expressions.Parameters
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ IInterfaceFieldDescriptor Type<TOutputType>(TOutputType type)

IInterfaceFieldDescriptor Type(Type type);

IInterfaceFieldDescriptor Ignore();
IInterfaceFieldDescriptor Ignore(bool ignore = true);

IInterfaceFieldDescriptor Argument(
NameString name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IObjectFieldDescriptor Argument(
NameString argumentName,
Action<IArgumentDescriptor> argumentDescriptor);

IObjectFieldDescriptor Ignore();
IObjectFieldDescriptor Ignore(bool ignore = true);

IObjectFieldDescriptor Resolver(
FieldResolverDelegate fieldResolver);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Types/Types/Descriptors/InterfaceFieldDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public IInterfaceFieldDescriptor DeprecationReason(string reason) =>
return this;
}

public new IInterfaceFieldDescriptor Ignore()
public new IInterfaceFieldDescriptor Ignore(bool ignore = true)
{
base.Ignore();
base.Ignore(ignore);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Types/Types/Descriptors/ObjectFieldDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ public IObjectFieldDescriptor DeprecationReason(string? reason) =>
return this;
}

public new IObjectFieldDescriptor Ignore()
public new IObjectFieldDescriptor Ignore(bool ignore = true)
{
base.Ignore();
base.Ignore(ignore);
return this;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Core/Types/Types/Descriptors/OutputFieldDescriptorBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HotChocolate.Language;
using HotChocolate.Properties;
using HotChocolate.Types.Descriptors.Definitions;
using System.Reflection;
using System.Linq;

namespace HotChocolate.Types.Descriptors
{
Expand Down Expand Up @@ -170,9 +170,9 @@ private void AddDeprectedDirective(string reason)
}
}

protected void Ignore()
protected void Ignore(bool ignore = true)
{
Definition.Ignore = true;
Definition.Ignore = ignore;
}

protected void Directive<T>(T directive)
Expand Down