title |
---|
Subscriptions |
A Subscription type cannot be stitched from downstream services so it must be defined directly in the gateway schema.
Warning: Subscription stitching is coming in v13
After adding a Subscription type to the gateway service, you may encounter an error when building the gateway schema.
1. The schema builder was unable to identify the query type of the schema. Either specify which type is the query type or set the schema builder to non-strict validation mode.
If you turn off strict validation and generate the schema, the schema
element won't include a query
field despite a Query type being defined.
services
.AddGraphQLServer()
.ModifyOptions(o =>
{
o.StrictValidation = false;
}
)
schema {
subscription: Subscription
}
type Query {
messages: [Message!]!
}
To resolve this issue, use the Schema Options to specify the QueryTypeName
and MutationTypeName
.
services
.AddGraphQLServer()
.ModifyOptions(o =>
{
o.QueryTypeName = "Query";
o.MutationTypeName = "Mutation";
}
)
Generating the schema again results in a valid schema.
schema {
query: Query
subscription: Subscription
}
type Query {
messages: [Message!]!
}
type Subscription {
onMessagePosted: Message!
}