Skip to content

Commit

Permalink
[Fusion] Aligned Root(Mutation|Query|Subscription)Used rules with spec (
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Dec 27, 2024
1 parent a9254e8 commit 538621a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
]
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
]
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
]
}
};
}
Expand Down

0 comments on commit 538621a

Please sign in to comment.