-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds pure resolver for stitching (#4702)
- Loading branch information
1 parent
5da845f
commit 8121059
Showing
7 changed files
with
113 additions
and
12 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
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
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
29 changes: 29 additions & 0 deletions
29
src/HotChocolate/Stitching/src/Stitching/Delegation/RemoteFieldHelper.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,29 @@ | ||
using System.Collections.Generic; | ||
using HotChocolate.Resolvers; | ||
using HotChocolate.Types; | ||
|
||
namespace HotChocolate.Stitching.Delegation; | ||
|
||
internal static class RemoteFieldHelper | ||
{ | ||
public static object? RemoteFieldResolver(IPureResolverContext context) | ||
{ | ||
if (!context.Selection.Field.Directives.Contains(DirectiveNames.Computed) && | ||
context.Parent<object>() is IReadOnlyDictionary<string, object> dict) | ||
{ | ||
var responseName = context.Selection.SyntaxNode.Alias == null | ||
? context.Selection.SyntaxNode.Name.Value | ||
: context.Selection.SyntaxNode.Alias.Value; | ||
|
||
dict.TryGetValue(responseName, out var obj); | ||
return DictionaryDeserializer.DeserializeResult( | ||
context.Selection.Type, | ||
obj, | ||
context.Service<InputParser>(), | ||
context.Path); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
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
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
21 changes: 21 additions & 0 deletions
21
...hing.Tests/Integration/__snapshots__/FederatedSchemaTests.AutoMerge_CompileOperation.snap
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,21 @@ | ||
{ | ||
... on Query { | ||
me @__execute(id: 0, kind: DEFAULT, type: COMPOSITE) { | ||
... on User { | ||
id @__execute(id: 2, kind: PURE, type: LEAF) | ||
name @__execute(id: 3, kind: PURE, type: LEAF) | ||
reviews @__execute(id: 4, kind: DEFAULT, type: COMPOSITE_LIST) { | ||
... on Review { | ||
body @__execute(id: 5, kind: PURE, type: LEAF) | ||
product @__execute(id: 6, kind: DEFAULT, type: COMPOSITE) { | ||
... on Product { | ||
upc @__execute(id: 7, kind: PURE, type: LEAF) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
local @__execute(id: 1, kind: DEFAULT, type: LEAF) | ||
} | ||
} |