Stitching Schema Merge #4892
Replies: 5 comments 9 replies
-
Here are some links for research of other systems: |
Beta Was this translation helpful? Give feedback.
-
The schema merger should get a list of schema documents and merge them into a single schema document. public interface ISchemaMerger
{
ISchemaDocument Merge(IEnumerable<ISchemaDocument> schemas)
} There might be rule sets for merging schema documents. We could either have multiple ISchemaMerger implementations or a single implementation that is initialized with a ruleset. |
Beta Was this translation helpful? Give feedback.
-
Was looking for ways to use the SDL primitives more for the merging definitions. For consideration:
|
Beta Was this translation helpful? Give feedback.
-
So, I have already done the following nodes: Finished: ArgumentNode A good example is For equality of a list of nodes use Take 2 or 3 nodes at once per PR. We will do the tests in the second round, I will create a template for the tests. Here is the list: OperationDefinitionNode (Vadim) Put you names behind the nodes you will be working on. |
Beta Was this translation helpful? Give feedback.
-
Regarding Tests. For each node, we now need tests that verify that the equality is correctly applied. The first test evaluates that the syntax node`s equality is correct when all nodes are in the same location. [Fact]
public void EqualsBooleanValueNode_SameLocation()
{
// arrange
var a = new BooleanValueNode(new Location(1, 1, 1, 1), false);
var b = new BooleanValueNode(new Location(1, 1, 1, 1), false);
var c = new BooleanValueNode(new Location(1, 1, 1, 1), true);
// act
var abResult = a.Equals(b);
var aaResult = a.Equals(a);
var acResult = a.Equals(c);
var aNullResult = a.Equals(default);
// assert
Assert.True(abResult);
Assert.True(aaResult);
Assert.False(acResult);
Assert.False(aNullResult);
} The second test ensures that the location has no impact on equality. Two boolean nodes in this case are the same if the parsed boolean value is the same. [Fact]
public void EqualsBooleanValueNode_DifferentLocation()
{
// arrange
var a = new BooleanValueNode(new Location(1, 1, 1, 1), false);
var b = new BooleanValueNode(new Location(2, 2, 2, 2), false);
var c = new BooleanValueNode(new Location(3, 3, 3, 3), true);
// act
var abResult = a.Equals(b);
var aaResult = a.Equals(a);
var acResult = a.Equals(c);
var aNullResult = a.Equals(default);
// assert
Assert.True(abResult);
Assert.True(aaResult);
Assert.False(acResult);
Assert.False(aNullResult);
} Lastly, we want to ensure that the location has no impact on the hashCode. [Fact]
public void CompareGetHashCode_With_Location()
{
// arrange
var a = new BooleanValueNode(new(1, 1, 1, 1), false);
var b = new BooleanValueNode(new(2, 2, 2, 2), false);
var c = new BooleanValueNode(new(1, 1, 1, 1), true);
var d = new BooleanValueNode(new(2, 2, 2, 2), true);
// act
var aHash = a.GetHashCode();
var bHash = b.GetHashCode();
var cHash = c.GetHashCode();
var dHash = d.GetHashCode();
// assert
Assert.Equal(aHash, bHash);
Assert.NotEqual(aHash, cHash);
Assert.Equal(cHash, dHash);
Assert.NotEqual(aHash, dHash);
} I will add another example for a more complex node. |
Beta Was this translation helpful? Give feedback.
-
Supergraph
The supergraph in Hot Chocolate represents an internal annotated GraphQL schema that is used by the Hot Chocolate gateway to serve up a distributed schema. The supergraph is the output of the schema merge process.
Directives
super-graph directives are always prefixed with
_hc_
so that we have a smaller risk of collisions with schema directives of the actual schema.super-graph annotations are not meant to be written by hand but are added during the schema merge process. With the new schema stitching version, we will allow the super-graph creation to be done by the gateway (like in the current version) or by tooling that runs outside of the gateway and pushes the super-graph to the gateway.
Bind
The bind directive is the most important directive and annotates where a certain piece of information can be retrieved from. With only the bind directive we can already create a fully qualified distributed schema.
Bind to a schema
Alternatively, a field can also be bound under a different name.
The bind as directive can be used also on arguments, enum values and type names.
Fetch
The fetch directive allows us to formulate a manual query to fetch data from a downstream service. This directive allows us to fuse the federated approach with the stitching approach.
The
... Fields
fragment spread is where we shall inject the request fields.Delegate
The delegate directive is used to allow legacy schemas to work with the new stitching engine by supporting the legacy path to refer to a downstream gateway.
DependsOn
The depends on directive allows us to express dependencies on other fields in or schema. This enforces the execution engine to first resolve the dependency data before being able to resolve the fie actual field.
Computed
The computed directive can be used in combination with custom directives of custom middleware and allows for the extensibility of the stitching engine. If a field is marked as computed the stitching engine will not handle it but expect it to be handled. However, computed can be used in combination with dependsOn.
@_hc_computed
Beta Was this translation helpful? Give feedback.
All reactions