-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RewriteType does not work with multiple rewrites (#2607)
- Loading branch information
1 parent
106a37a
commit 3ea83c9
Showing
3 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/HotChocolate/Stitching/test/Stitching.Tests/Configuration/ContextDataExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using HotChocolate.Configuration; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
using HotChocolate.Types.Descriptors.Definitions; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Stitching.Configuration | ||
{ | ||
public class ContextDataExtensionsTest | ||
{ | ||
[Fact] | ||
public void AddNameLookup_Single() | ||
{ | ||
// arrange | ||
ISchemaBuilder schemaBuilder = SchemaBuilder.New().AddQueryType<CustomQueryType>(); | ||
|
||
// act | ||
schemaBuilder.AddNameLookup("OriginalType1", "NewType1", "Schema1"); | ||
schemaBuilder.AddNameLookup("OriginalType2", "NewType2", "Schema2"); | ||
|
||
// assert | ||
IReadOnlyDictionary<(NameString, NameString), NameString> lookup = | ||
schemaBuilder | ||
.Create() | ||
.GetType<CustomQueryType>(nameof(CustomQueryType)) | ||
.Context | ||
.GetNameLookup(); | ||
Assert.Equal("OriginalType1", lookup[("NewType1", "Schema1")]); | ||
Assert.Equal("OriginalType2", lookup[("NewType2", "Schema2")]); | ||
} | ||
|
||
[Fact] | ||
public void AddNameLookup_Multiple() | ||
{ | ||
// arrange | ||
ISchemaBuilder schemaBuilder = SchemaBuilder.New().AddQueryType<CustomQueryType>(); | ||
var dict = new Dictionary<(NameString, NameString), NameString> | ||
{ | ||
{ ("NewType1", "Schema1"), "OriginalType1" }, | ||
{ ("NewType2", "Schema2"), "OriginalType2" } | ||
}; | ||
|
||
// act | ||
schemaBuilder.AddNameLookup(dict); | ||
|
||
// assert | ||
IReadOnlyDictionary<(NameString, NameString), NameString> lookup = | ||
schemaBuilder | ||
.Create() | ||
.GetType<CustomQueryType>(nameof(CustomQueryType)) | ||
.Context | ||
.GetNameLookup(); | ||
Assert.Equal("OriginalType1", lookup[("NewType1", "Schema1")]); | ||
Assert.Equal("OriginalType2", lookup[("NewType2", "Schema2")]); | ||
} | ||
|
||
public class CustomQueryType : ObjectType | ||
{ | ||
public IDescriptorContext Context { get; set; } | ||
|
||
protected override void Configure(IObjectTypeDescriptor descriptor) | ||
{ | ||
descriptor.Field("foo").Resolve("bar"); | ||
} | ||
|
||
protected override ObjectTypeDefinition CreateDefinition(ITypeDiscoveryContext context) | ||
{ | ||
Context = context.DescriptorContext; | ||
|
||
return base.CreateDefinition(context); | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...test/Stitching.Tests/Configuration/HotChocolateStitchingRequestExecutorExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using HotChocolate.Configuration; | ||
using HotChocolate.Execution; | ||
using HotChocolate.Execution.Configuration; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
using HotChocolate.Types.Descriptors.Definitions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Stitching.Configuration | ||
{ | ||
public class HotChocolateStitchingRequestExecutorExtensionsTests | ||
{ | ||
[Fact] | ||
public async Task RewriteType() | ||
{ | ||
// arrange | ||
IRequestExecutorBuilder executorBuilder = | ||
new ServiceCollection().AddGraphQL().AddQueryType<CustomQueryType>(); | ||
|
||
// act | ||
executorBuilder.RewriteType("OriginalType1", "NewType1", "Schema1"); | ||
executorBuilder.RewriteType("OriginalType2", "NewType2", "Schema2"); | ||
|
||
// assert | ||
ISchema schema = await executorBuilder.BuildSchemaAsync(); | ||
IReadOnlyDictionary<(NameString, NameString), NameString> lookup = | ||
schema | ||
.GetType<CustomQueryType>(nameof(CustomQueryType)) | ||
.Context | ||
.GetNameLookup(); | ||
Assert.Equal("OriginalType1", lookup[("NewType1", "Schema1")]); | ||
Assert.Equal("OriginalType2", lookup[("NewType2", "Schema2")]); | ||
} | ||
} | ||
|
||
public class CustomQueryType : ObjectType | ||
{ | ||
public IDescriptorContext Context { get; set; } | ||
|
||
protected override void Configure(IObjectTypeDescriptor descriptor) | ||
{ | ||
descriptor.Field("foo").Resolve("bar"); | ||
} | ||
|
||
protected override ObjectTypeDefinition CreateDefinition(ITypeDiscoveryContext context) | ||
{ | ||
Context = context.DescriptorContext; | ||
|
||
return base.CreateDefinition(context); | ||
} | ||
} | ||
} |