Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class RequirementsValidator(
public ImmutableArray<SatisfiabilityError> Validate(
SelectionSetNode requirements,
MutableObjectTypeDefinition contextType,
SatisfiabilityPathItem parentPathItem,
SatisfiabilityPathItem? parentPathItem,
string excludeSchemaName,
SatisfiabilityPath? cycleDetectionPath = null)
{
Expand Down Expand Up @@ -384,12 +384,17 @@ internal sealed class RequirementsValidatorContext
{
public RequirementsValidatorContext(
MutableObjectTypeDefinition contextType,
SatisfiabilityPathItem parentPathItem,
SatisfiabilityPathItem? parentPathItem,
string excludeSchemaName,
SatisfiabilityPath? cycleDetectionPath = null)
{
TypeContext.Push(contextType);
Path.Push(parentPathItem);

if (parentPathItem is not null)
{
Path.Push(parentPathItem);
}

ExcludeSchemaName = excludeSchemaName;
CycleDetectionPath = cycleDetectionPath ?? [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void VisitOutputField(
_requirementsValidator.Validate(
requirements,
type,
context.Path.Peek(),
previousPathItem,
excludeSchemaName: schemaName);

if (requirementErrors.Length != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,39 @@ type Section {
""");
}

[Fact]
public void RootRequirement()
{
// arrange
var merger = new SourceSchemaMerger(
CreateSchemaDefinitions(
[
"""
# Schema A
type Query {
optionalField: String
}
""",
"""
# Schema B
type Query {
requiredField(value: String @require(field: "optionalField")): String!
}
"""
]),
new SourceSchemaMergerOptions { AddFusionDefinitions = false });

var schema = merger.Merge().Value;
var log = new CompositionLog();
var satisfiabilityValidator = new SatisfiabilityValidator(schema, log);

// act
var result = satisfiabilityValidator.Validate();

// assert
Assert.True(result.IsSuccess);
}

[Theory]
[MemberData(nameof(GlobalObjectIdentificationExamplesData))]
public void GlobalObjectIdentification_Examples(string[] sdl, bool success, string? logs = null)
Expand Down
Loading