Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -78,6 +78,13 @@ public CompositionResult<MutableSchemaDefinition> Compose()
return enrichmentResult.Errors;
}

// Prune unreachable definitions from each source schema before validation, so types
// stripped by @excludeByTag (or otherwise unreferenced) are not validated or merged.
foreach (var schema in schemas)
{
schema.RemoveUnreferencedDefinitions(schemas);
Comment thread
tobias-tengler marked this conversation as resolved.
Outdated
Comment thread
tobias-tengler marked this conversation as resolved.
Outdated
}

// Validate Source Schemas
var validationResult =
new SourceSchemaValidator(schemas, s_sourceSchemaRules, _log).Validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,76 @@ type Product {
entry.Message);
}

[Fact]
public void Compose_OrphanedTypeAfterTagExclusion_DoesNotProduceShareableError()
{
// arrange
// Schema A's Product is only reachable via Mutation. When Mutation is removed by
// tag exclusion, Product becomes orphaned. Without pruning, Product.name would
// collide with Schema B's Product.name and trigger an InvalidFieldSharing error.
var schemaComposer = new SchemaComposer(
[
new SourceSchemaText(
"A",
"""
type Query {
book(id: ID!): Book @lookup
}

type Mutation @tag(name: "internal") {
createProduct(name: String!): Product
}

type Book {
id: ID!
title: String!
}

type Product {
id: ID!
name: String!
}

directive @tag(name: String!) repeatable on OBJECT
"""),
new SourceSchemaText(
"B",
"""
type Query {
productById(id: ID!): Product @lookup
}

type Product {
id: ID!
name: String!
}
""")
],
new SchemaComposerOptions
{
Merger = { AddFusionDefinitions = false },
SourceSchemas =
{
["A"] = new SourceSchemaOptions
{
Preprocessor = new SourceSchemaPreprocessorOptions
{
ExcludeByTag = ["internal"]
}
}
}
},
new CompositionLog());

// act
var result = schemaComposer.Compose();

// assert
Assert.True(result.IsSuccess);
Assert.False(result.Value.Types.ContainsName("Mutation"));
Assert.True(result.Value.Types.ContainsName("Product"));
}

[Fact]
public void Compose_WithExtensions_AppliesExtensions()
{
Expand Down
Loading