Skip to content

Commit

Permalink
Fixed: Relay node field did not show in SDL (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Oct 29, 2019
1 parent 6cf4e40 commit 94cc778
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/Core/Types.Tests/Types/Relay/NodeResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public async Task NodeResolverObject_ResolveNode_DynamicFieldObject()
result.MatchSnapshot();
}


public class Query
{
public Entity GetEntity(string name) => new Entity { Name = name };
Expand Down
26 changes: 13 additions & 13 deletions src/Core/Types.Tests/Types/Relay/QueryableConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class QueryableConnectionTests
public async Task TakeFirst()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var pagingDetails = new PagingDetails
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public async Task TakeFirst()
public async Task TakeLast()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var pagingDetails = new PagingDetails
{
Expand Down Expand Up @@ -94,10 +94,10 @@ public async Task TakeLast()
public async Task TakeFirstAfter()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var connectionFactory = new QueryableConnectionResolver<string>(
list.AsQueryable(), new PagingDetails {First = 1});
list.AsQueryable(), new PagingDetails { First = 1 });

Connection<string> connection = await connectionFactory.ResolveAsync(
CancellationToken.None);
Expand Down Expand Up @@ -141,11 +141,11 @@ public async Task TakeFirstAfter()
public async Task TakeTwoAfterSecondTime()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

// 1. Page
var connectionFactory = new QueryableConnectionResolver<string>(
list.AsQueryable(), new PagingDetails {First = 2});
list.AsQueryable(), new PagingDetails { First = 2 });

Connection<string> connection = await connectionFactory.ResolveAsync(
CancellationToken.None);
Expand Down Expand Up @@ -203,10 +203,10 @@ public async Task TakeTwoAfterSecondTime()
public async Task TakeLastBefore()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var connectionFactory = new QueryableConnectionResolver<string>(
list.AsQueryable(), new PagingDetails {First = 5});
list.AsQueryable(), new PagingDetails { First = 5 });

Connection<string> connection = await connectionFactory.ResolveAsync(
CancellationToken.None);
Expand Down Expand Up @@ -250,7 +250,7 @@ public async Task TakeLastBefore()
public async Task HasNextPage_True()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var pagingDetails = new PagingDetails
{
Expand All @@ -272,7 +272,7 @@ public async Task HasNextPage_True()
public async Task HasNextPage_False()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var pagingDetails = new PagingDetails
{
Expand All @@ -294,10 +294,10 @@ public async Task HasNextPage_False()
public async Task HasPrevious_True()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var connectionFactory = new QueryableConnectionResolver<string>(
list.AsQueryable(), new PagingDetails {First = 1});
list.AsQueryable(), new PagingDetails { First = 1 });

Connection<string> connection = await connectionFactory.ResolveAsync(
CancellationToken.None);
Expand All @@ -323,7 +323,7 @@ public async Task HasPrevious_True()
public async Task HasPrevious_False()
{
// arrange
var list = new List<string> {"a", "b", "c", "d", "e", "f", "g",};
var list = new List<string> { "a", "b", "c", "d", "e", "f", "g", };

var pagingDetails = new PagingDetails();

Expand Down
44 changes: 44 additions & 0 deletions src/Core/Types.Tests/Types/Relay/RelaySchemaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Threading.Tasks;
using Snapshooter.Xunit;
using Xunit;

namespace HotChocolate.Types.Relay
{
public class RelaySchemaTests
{
[Fact]
public void EnableRelay_Node_Field_On_Query_Exists()
{
// arrange
// act
ISchema schema = SchemaBuilder.New()
.AddQueryType<QueryType>()
.EnableRelaySupport()
.Create();

// assert
schema.ToString().MatchSnapshot();
}

public class QueryType
: ObjectType
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Field("some").Type<SomeType>().Resolver(new object());
}
}

public class SomeType
: ObjectType
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Name("Some")
.AsNode()
.NodeResolver((context, id) => Task.FromResult(new object()));
descriptor.Field("id").Type<NonNullType<IdType>>().Resolver("bar");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
schema {
query: QueryType
}

"The node interface is implemented by entities that have a gloabl unique identifier."
interface Node {
id: ID!
}

type QueryType {
node(id: ID!): Node
some: Some
}

type Some implements Node {
id: ID!
}

"The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID."
scalar ID
3 changes: 1 addition & 2 deletions src/Core/Types/Types/ObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ private void CompleteInterfaces(
{
// TODO : resources
context.ReportError(SchemaErrorBuilder.New()
.SetMessage(
"COULD NOT RESOLVE INTERFACE")
.SetMessage("COULD NOT RESOLVE INTERFACE")
.SetCode(ErrorCodes.Schema.MissingType)
.SetTypeSystemObject(this)
.AddSyntaxNode(SyntaxNode)
Expand Down
7 changes: 2 additions & 5 deletions src/Core/Types/Types/Relay/NodeField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ internal NodeField(IDescriptorContext context)
{
}

public override bool IsIntrospectionField { get; } = true;

private static ObjectFieldDefinition CreateDefinition(
IDescriptorContext context)
{
var descriptor = ObjectFieldDescriptor
.New(context, "node");
var descriptor = ObjectFieldDescriptor.New(context, "node");

IIdSerializer _serializer = null;

descriptor
.Argument("id", a => a.Type<NonNullType<IdType>>())
.Type<NonNullType<NodeType>>()
.Type<NodeType>()
.Resolver(async ctx =>
{
if (_serializer is null)
Expand Down

0 comments on commit 94cc778

Please sign in to comment.