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

Fixed type rename issue when types where uses in nun-null types. #988

Merged
merged 1 commit into from Aug 9, 2019
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
139 changes: 139 additions & 0 deletions src/Core/Language.Tests/AST/ListTypeNodeTests.cs
@@ -0,0 +1,139 @@
using System;
using Xunit;

namespace HotChocolate.Language
{
public class ListTypeNodeTests
{
[Fact]
public void Create_With_Type()
{
// arrange
var namedType = new NamedTypeNode("abc");

// act
var type = new ListTypeNode(namedType);

// assert
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Type_Where_Type_Is_Null()
{
// arrange
// act
Action action = () => new ListTypeNode(null);

// assert
Assert.Throws<ArgumentNullException>(action);
}

[Fact]
public void Create_With_Location_And_Type()
{
// arrange
var location = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");

// act
var type = new ListTypeNode(location, namedType);

// assert
Assert.Equal(location, type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Location_And_Type_Where_Location_Is_Null()
{
// arrange
var namedType = new NamedTypeNode("abc");

// act
var type = new ListTypeNode(null, namedType);

// assert
Assert.Null(type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Location_And_Type_Where_Type_Is_Null()
{
// arrange
var location = new Location(1, 1, 1, 1);

// act
Action action = () => new ListTypeNode(location, null);

// assert
Assert.Throws<ArgumentNullException>(action);
}

[Fact]
public void WithLocation()
{
// arrange
var initialLocation = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");
var type = new ListTypeNode(initialLocation, namedType);

// act
var newLocation = new Location(2, 2, 2, 2);
type = type.WithLocation(newLocation);

// assert
Assert.Equal(newLocation, type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void WithLocation_Where_Location_Is_Null()
{
// arrange
var initialLocation = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");
var type = new ListTypeNode(initialLocation, namedType);

// act
type = type.WithLocation(null);

// assert
Assert.Null(type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void WithType()
{
// arrange
var location = new Location(1, 1, 1, 1);
var initialType = new NamedTypeNode("abc");
var type = new ListTypeNode(location, initialType);

// act
var newType = new NamedTypeNode("def");
type = type.WithType(newType);

// assert
Assert.Equal(location, type.Location);
Assert.Equal(newType, type.Type);
}

[Fact]
public void WithType_Where_Type_Is_Null()
{
// arrange
var location = new Location(1, 1, 1, 1);
var initialType = new NamedTypeNode("abc");
var type = new ListTypeNode(location, initialType);

// act
Action action = () => type.WithType(null);

// assert
Assert.Throws<ArgumentNullException>(action);
}
}
}
139 changes: 139 additions & 0 deletions src/Core/Language.Tests/AST/NonNullTypeNodeTests.cs
@@ -0,0 +1,139 @@
using System;
using Xunit;

namespace HotChocolate.Language
{
public class NonNullTypeNodeTests
{
[Fact]
public void Create_With_Type()
{
// arrange
var namedType = new NamedTypeNode("abc");

// act
var type = new NonNullTypeNode(namedType);

// assert
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Type_Where_Type_Is_Null()
{
// arrange
// act
Action action = () => new NonNullTypeNode(null);

// assert
Assert.Throws<ArgumentNullException>(action);
}

[Fact]
public void Create_With_Location_And_Type()
{
// arrange
var location = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");

// act
var type = new NonNullTypeNode(location, namedType);

// assert
Assert.Equal(location, type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Location_And_Type_Where_Location_Is_Null()
{
// arrange
var namedType = new NamedTypeNode("abc");

// act
var type = new NonNullTypeNode(null, namedType);

// assert
Assert.Null(type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void Create_With_Location_And_Type_Where_Type_Is_Null()
{
// arrange
var location = new Location(1, 1, 1, 1);

// act
Action action = () => new NonNullTypeNode(location, null);

// assert
Assert.Throws<ArgumentNullException>(action);
}

[Fact]
public void WithLocation()
{
// arrange
var initialLocation = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");
var type = new NonNullTypeNode(initialLocation, namedType);

// act
var newLocation = new Location(2, 2, 2, 2);
type = type.WithLocation(newLocation);

// assert
Assert.Equal(newLocation, type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void WithLocation_Where_Location_Is_Null()
{
// arrange
var initialLocation = new Location(1, 1, 1, 1);
var namedType = new NamedTypeNode("abc");
var type = new NonNullTypeNode(initialLocation, namedType);

// act
type = type.WithLocation(null);

// assert
Assert.Null(type.Location);
Assert.Equal(namedType, type.Type);
}

[Fact]
public void WithType()
{
// arrange
var location = new Location(1, 1, 1, 1);
var initialType = new NamedTypeNode("abc");
var type = new NonNullTypeNode(location, initialType);

// act
var newType = new NamedTypeNode("def");
type = type.WithType(newType);

// assert
Assert.Equal(location, type.Location);
Assert.Equal(newType, type.Type);
}

[Fact]
public void WithType_Where_Type_Is_Null()
{
// arrange
var location = new Location(1, 1, 1, 1);
var initialType = new NamedTypeNode("abc");
var type = new NonNullTypeNode(location, initialType);

// act
Action action = () => type.WithType(null);

// assert
Assert.Throws<ArgumentNullException>(action);
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Language/AST/NonNullTypeNode.cs
Expand Up @@ -30,7 +30,7 @@ public NonNullTypeNode WithLocation(Location location)

public NonNullTypeNode WithType(INullableTypeNode type)
{
return new NonNullTypeNode(Location, Type);
return new NonNullTypeNode(Location, type);
}

public bool Equals(NonNullTypeNode other)
Expand Down
20 changes: 20 additions & 0 deletions src/Stitching/Stitching.Tests/Merge/SchemaMergerTests.cs
Expand Up @@ -309,6 +309,26 @@ public void RenameReferencingType()
SnapshotNameExtension.Create("B"));
}

[Fact]
public void Rename_Type_With_Various_Variants()
{
// arrange
DocumentNode initial =
Utf8GraphQLParser.Parse(
"type A { b1: B! b2: [B!] b3: [B] b4: [B!]! } " +
"type B implements C { c: String } " +
"interface C { c: String }");

// act
DocumentNode merged = SchemaMerger.New()
.AddSchema("A", initial)
.RenameType("A", "B", "Foo")
.Merge();

// assert
SchemaSyntaxSerializer.Serialize(merged).MatchSnapshot();
}

[Fact]
public void FieldDefinitionDoesNotHaveSameTypeShape()
{
Expand Down
@@ -0,0 +1,14 @@
type A @source(name: "A", schema: "A") {
b1: Foo!
b2: [Foo!]
b3: [Foo]
b4: [Foo!]!
}

type Foo implements C @source(name: "B", schema: "A") {
c: String
}

interface C @source(name: "C", schema: "A") {
c: String
}
@@ -1,4 +1,3 @@
using System;
using HotChocolate.Language;

namespace HotChocolate.Stitching.Merge.Rewriters
Expand Down
2 changes: 0 additions & 2 deletions src/Stitching/Stitching/Merge/TypeReferenceRewriter.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HotChocolate;
using HotChocolate.Language;
using HotChocolate.Resolvers;

namespace HotChocolate.Stitching.Merge
{
Expand Down
1 change: 0 additions & 1 deletion src/Stitching/Stitching/StitchingBuilder.Factory.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Execution;
using HotChocolate.Execution.Configuration;
using HotChocolate.Language;
using HotChocolate.Stitching.Client;
using HotChocolate.Stitching.Delegation;
Expand Down