File tree 2 files changed +52
-2
lines changed
src/Execution/DependencyInjection
test/Types.Tests/Types/Relay
2 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ public static partial class SchemaRequestExecutorBuilderExtensions
19
19
public static IRequestExecutorBuilder AddGlobalObjectIdentification (
20
20
this IRequestExecutorBuilder builder )
21
21
{
22
- builder . AddDefaultNodeIdSerializer ( ) ;
22
+ if ( builder . Services . All ( t => t . ServiceType != typeof ( INodeIdSerializer ) ) )
23
+ {
24
+ builder . AddDefaultNodeIdSerializer ( ) ;
25
+ }
26
+
23
27
return builder . ConfigureSchema ( c => c . AddGlobalObjectIdentification ( ) ) ;
24
28
}
25
29
@@ -39,7 +43,11 @@ public static IRequestExecutorBuilder AddGlobalObjectIdentification(
39
43
this IRequestExecutorBuilder builder ,
40
44
bool registerNodeInterface )
41
45
{
42
- builder . AddDefaultNodeIdSerializer ( ) ;
46
+ if ( builder . Services . All ( t => t . ServiceType != typeof ( INodeIdSerializer ) ) )
47
+ {
48
+ builder . AddDefaultNodeIdSerializer ( ) ;
49
+ }
50
+
43
51
return builder . ConfigureSchema ( c => c . AddGlobalObjectIdentification ( registerNodeInterface ) ) ;
44
52
}
45
53
Original file line number Diff line number Diff line change
1
+ using Microsoft . Extensions . DependencyInjection ;
2
+
3
+ namespace HotChocolate . Types . Relay ;
4
+
5
+ public class NodeIdSerializerTests
6
+ {
7
+ [ Fact ]
8
+ public void Registered_NodeIdSerializer_Should_Not_Be_Overwritten_By_AddGlobalObjectIdentification ( )
9
+ {
10
+ // arrange
11
+ var provider = new ServiceCollection ( )
12
+ . AddGraphQL ( )
13
+ . AddLegacyNodeIdSerializer ( )
14
+ . AddGlobalObjectIdentification ( )
15
+ . Services . BuildServiceProvider ( ) ;
16
+
17
+ // act
18
+ var serializer = provider . GetRequiredService < INodeIdSerializer > ( ) ;
19
+
20
+ // assert
21
+ Assert . IsType < LegacyNodeIdSerializer > ( serializer ) ;
22
+ }
23
+
24
+ [ Fact ]
25
+ public void
26
+ Registered_DefaultNodeIdSerializer_With_OutputNewIdFormat_Should_Not_Be_Overwritten_By_AddGlobalObjectIdentification ( )
27
+ {
28
+ // arrange
29
+ var provider = new ServiceCollection ( )
30
+ . AddGraphQL ( )
31
+ . AddDefaultNodeIdSerializer ( outputNewIdFormat : false )
32
+ . AddGlobalObjectIdentification ( )
33
+ . Services . BuildServiceProvider ( ) ;
34
+
35
+ // act
36
+ var serializer = provider . GetRequiredService < INodeIdSerializer > ( ) ;
37
+ var serializedId = serializer . Format ( "Foo" , 32 ) ;
38
+
39
+ // assert
40
+ Assert . Equal ( "Rm9vCmkzMg==" , serializedId ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments