Skip to content

Commit

Permalink
Fix #842 - merge schema with custom scalar usage (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkah authored Jun 14, 2021
1 parent e41d82c commit 439bf3e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/graphql/Tools/MergeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ public static void Schemas(SchemaBuilder target, params ISchema[] schemas)

public static void Schema(SchemaBuilder target, ISchema right)
{
foreach (var rightType in right.QueryTypes<ScalarType>())
MergeScalarType(right, target, rightType);

foreach (var rightType in right.QueryTypes<EnumType>())
MergeEnumType(right, target, rightType);

foreach (var rightType in right.QueryTypes<InputObjectType>())
MergeInputType(right, target, rightType);

foreach (var rightType in right.QueryTypes<ScalarType>())
MergeScalarType(right, target, rightType);


foreach (var directiveType in right.QueryDirectiveTypes())
{
target.TryGetDirective(directiveType.Name, out var leftDirective);
Expand Down
56 changes: 56 additions & 0 deletions tests/graphql.tests/Tools/MakeExecutableWithIntrospectionFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Tanka.GraphQL.SchemaBuilding;
using Tanka.GraphQL.SDL;
using Tanka.GraphQL.Tools;
using Tanka.GraphQL.TypeSystem;
using Tanka.GraphQL.TypeSystem.ValueSerialization;
using Xunit;

namespace Tanka.GraphQL.Tests.Tools
{
public class MakeExecutableWithIntrospectionFacts
{
[Fact]
public async Task WithCustomScalar()
{
/* Given */
var builder = new SchemaBuilder();
await builder.SdlAsync(@"
scalar Date
input InputTest {
timestamp: Date
}
type Query {
getDate(date: Date): String
}
type Mutation {
addDate(date: Date, inputTest: InputTest): String
}
schema {
query: Query
mutation: Mutation
subscription: Subscription
}");


/* When */
var schema = SchemaTools.MakeExecutableSchemaWithIntrospection(
builder,
converters: new Dictionary<string, IValueConverter>()
{
["Date"] = new StringConverter()
});

/* Then */
var date = schema.GetNamedType("Date");

Assert.NotNull(date);
Assert.IsType<ScalarType>(date);
}
}
}
38 changes: 38 additions & 0 deletions tests/graphql.tests/Tools/MergeSchemasFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Tanka.GraphQL.SDL;
using Tanka.GraphQL.Tools;
using Tanka.GraphQL.TypeSystem;
using Tanka.GraphQL.TypeSystem.ValueSerialization;
using Xunit;

namespace Tanka.GraphQL.Tests.Tools
Expand Down Expand Up @@ -163,5 +164,42 @@ type Query {
var field = schema.GetField("Query", "color");
Assert.Equal(newUnionType, field.Type);
}

[Fact]
public void Merge_schema_with_new_CustomScalar()
{
/* Given */
var newTypes = new SchemaBuilder()
.Sdl(@"
scalar Date
input InputTest {
timestamp: Date
}
type Query {
useRaw(date: Date!): Int
useWithInput(inputWithDate: InputTest!): Int
}
")
.Include("Date", new StringConverter())
.Build();

var builder = new SchemaBuilder()
.Sdl(@"
schema {
query: Query
}
");


/* When */
var schema = builder.Merge(newTypes)
.Build();

/* Then */
var newScalarType = schema.GetNamedType<ScalarType>("Date");
Assert.NotNull(newScalarType);
}
}
}

0 comments on commit 439bf3e

Please sign in to comment.