Skip to content

Commit 439bf3e

Browse files
authored
Fix #842 - merge schema with custom scalar usage (#895)
1 parent e41d82c commit 439bf3e

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

src/graphql/Tools/MergeTool.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ public static void Schemas(SchemaBuilder target, params ISchema[] schemas)
1515

1616
public static void Schema(SchemaBuilder target, ISchema right)
1717
{
18+
foreach (var rightType in right.QueryTypes<ScalarType>())
19+
MergeScalarType(right, target, rightType);
20+
1821
foreach (var rightType in right.QueryTypes<EnumType>())
1922
MergeEnumType(right, target, rightType);
2023

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

24-
foreach (var rightType in right.QueryTypes<ScalarType>())
25-
MergeScalarType(right, target, rightType);
26-
27-
2827
foreach (var directiveType in right.QueryDirectiveTypes())
2928
{
3029
target.TryGetDirective(directiveType.Name, out var leftDirective);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Tanka.GraphQL.SchemaBuilding;
4+
using Tanka.GraphQL.SDL;
5+
using Tanka.GraphQL.Tools;
6+
using Tanka.GraphQL.TypeSystem;
7+
using Tanka.GraphQL.TypeSystem.ValueSerialization;
8+
using Xunit;
9+
10+
namespace Tanka.GraphQL.Tests.Tools
11+
{
12+
public class MakeExecutableWithIntrospectionFacts
13+
{
14+
[Fact]
15+
public async Task WithCustomScalar()
16+
{
17+
/* Given */
18+
var builder = new SchemaBuilder();
19+
await builder.SdlAsync(@"
20+
scalar Date
21+
22+
input InputTest {
23+
timestamp: Date
24+
}
25+
26+
type Query {
27+
getDate(date: Date): String
28+
}
29+
30+
type Mutation {
31+
addDate(date: Date, inputTest: InputTest): String
32+
}
33+
34+
schema {
35+
query: Query
36+
mutation: Mutation
37+
subscription: Subscription
38+
}");
39+
40+
41+
/* When */
42+
var schema = SchemaTools.MakeExecutableSchemaWithIntrospection(
43+
builder,
44+
converters: new Dictionary<string, IValueConverter>()
45+
{
46+
["Date"] = new StringConverter()
47+
});
48+
49+
/* Then */
50+
var date = schema.GetNamedType("Date");
51+
52+
Assert.NotNull(date);
53+
Assert.IsType<ScalarType>(date);
54+
}
55+
}
56+
}

tests/graphql.tests/Tools/MergeSchemasFacts.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Tanka.GraphQL.SDL;
44
using Tanka.GraphQL.Tools;
55
using Tanka.GraphQL.TypeSystem;
6+
using Tanka.GraphQL.TypeSystem.ValueSerialization;
67
using Xunit;
78

89
namespace Tanka.GraphQL.Tests.Tools
@@ -163,5 +164,42 @@ type Query {
163164
var field = schema.GetField("Query", "color");
164165
Assert.Equal(newUnionType, field.Type);
165166
}
167+
168+
[Fact]
169+
public void Merge_schema_with_new_CustomScalar()
170+
{
171+
/* Given */
172+
var newTypes = new SchemaBuilder()
173+
.Sdl(@"
174+
scalar Date
175+
176+
input InputTest {
177+
timestamp: Date
178+
}
179+
180+
type Query {
181+
useRaw(date: Date!): Int
182+
useWithInput(inputWithDate: InputTest!): Int
183+
}
184+
")
185+
.Include("Date", new StringConverter())
186+
.Build();
187+
188+
var builder = new SchemaBuilder()
189+
.Sdl(@"
190+
schema {
191+
query: Query
192+
}
193+
");
194+
195+
196+
/* When */
197+
var schema = builder.Merge(newTypes)
198+
.Build();
199+
200+
/* Then */
201+
var newScalarType = schema.GetNamedType<ScalarType>("Date");
202+
Assert.NotNull(newScalarType);
203+
}
166204
}
167205
}

0 commit comments

Comments
 (0)