diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootMutationUsedRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootMutationUsedRule.cs index 90fa25f6f15..9c7bc3ab2ae 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootMutationUsedRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootMutationUsedRule.cs @@ -19,13 +19,22 @@ public void Handle(SchemaEvent @event, CompositionContext context) var schema = @event.Schema; var rootMutation = schema.MutationType; - if (rootMutation is not null && rootMutation.Name != WellKnownTypeNames.Mutation) + if (rootMutation is not null) { - context.Log.Write(RootMutationUsed(schema)); + if (rootMutation.Name != WellKnownTypeNames.Mutation) + { + context.Log.Write(RootMutationUsed(schema)); + } } + else + { + var namedMutationType = + schema.Types.FirstOrDefault(t => t.Name == WellKnownTypeNames.Mutation); - // An object type named 'Mutation' will be set as the root mutation type if it has not yet - // been defined, so it's not necessary to check for this type in the absence of a root - // mutation type. + if (namedMutationType is not null) + { + context.Log.Write(RootMutationUsed(schema)); + } + } } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootQueryUsedRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootQueryUsedRule.cs index 4d452fda430..4477bfaf735 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootQueryUsedRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootQueryUsedRule.cs @@ -19,13 +19,22 @@ public void Handle(SchemaEvent @event, CompositionContext context) var schema = @event.Schema; var rootQuery = schema.QueryType; - if (rootQuery is not null && rootQuery.Name != WellKnownTypeNames.Query) + if (rootQuery is not null) { - context.Log.Write(RootQueryUsed(schema)); + if (rootQuery.Name != WellKnownTypeNames.Query) + { + context.Log.Write(RootQueryUsed(schema)); + } } + else + { + var namedQueryType = + schema.Types.FirstOrDefault(t => t.Name == WellKnownTypeNames.Query); - // An object type named 'Query' will be set as the root query type if it has not yet been - // defined, so it's not necessary to check for this type in the absence of a root query - // type. + if (namedQueryType is not null) + { + context.Log.Write(RootQueryUsed(schema)); + } + } } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootSubscriptionUsedRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootSubscriptionUsedRule.cs index 75a3be98811..4a6dc2f9097 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootSubscriptionUsedRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RootSubscriptionUsedRule.cs @@ -20,14 +20,22 @@ public void Handle(SchemaEvent @event, CompositionContext context) var schema = @event.Schema; var rootSubscription = schema.SubscriptionType; - if (rootSubscription is not null - && rootSubscription.Name != WellKnownTypeNames.Subscription) + if (rootSubscription is not null) { - context.Log.Write(RootSubscriptionUsed(schema)); + if (rootSubscription.Name != WellKnownTypeNames.Subscription) + { + context.Log.Write(RootSubscriptionUsed(schema)); + } } + else + { + var namedSubscriptionType = + schema.Types.FirstOrDefault(t => t.Name == WellKnownTypeNames.Subscription); - // An object type named 'Subscription' will be set as the root subscription type if it has - // not yet been defined, so it's not necessary to check for this type in the absence of a - // root subscription type. + if (namedSubscriptionType is not null) + { + context.Log.Write(RootSubscriptionUsed(schema)); + } + } } } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs index cd4ba5a35d9..4e2e6ee7c2d 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs @@ -91,6 +91,15 @@ type Mutation { [ "The root mutation type in schema 'A' must be named 'Mutation'." ] + }, + // A type named 'Mutation' is not the root mutation type. + { + [ + "scalar Mutation" + ], + [ + "The root mutation type in schema 'A' must be named 'Mutation'." + ] } }; } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs index 6c15b1aa724..282fecb9388 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs @@ -91,6 +91,15 @@ type Query { [ "The root query type in schema 'A' must be named 'Query'." ] + }, + // A type named 'Query' is not the root query type. + { + [ + "scalar Query" + ], + [ + "The root query type in schema 'A' must be named 'Query'." + ] } }; } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs index 0e8cba67fee..be7a0efd121 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs @@ -91,6 +91,15 @@ type Subscription { [ "The root subscription type in schema 'A' must be named 'Subscription'." ] + }, + // A type named 'Subscription' is not the root subscription type. + { + [ + "scalar Subscription" + ], + [ + "The root subscription type in schema 'A' must be named 'Subscription'." + ] } }; }