graphql-dotnet: Error about duplicate union type.
Summary
I sometimes stumble upon a strange error in our GraphQL schema related to union types. I did my best to search for answer but haven’t find anyone with a similar issue so far, which warrants me to create this issue.
Relevant information
The error is related to union types and looks as following:
{
"error": "Invalid schema Error:\nUnion type ProductDrawsResult can only include type UpstreamServiceFailed once."
}
I’ve seen this happen before for other union types in our schema, so it does not seem related to this specific type.
I’ll post the code of this type nonetheless for you guys to take a look:
internal sealed class ProductDrawsResultType : UnionGraphType
{
public ProductDrawsResultType()
{
Name = "ProductDrawsResult";
Type<ProductDrawsType>();
Type<UpstreamServiceFailedType>();
}
}
The query still works as expected, but I can’t load the schema.
It puzzles me, does anyone have a clue?
Environment (if relevant)
GraphQL 4.7.1, OS Linux, .NET 6.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (18 by maintainers)
Just wanted to update you guys that through changing the schema and all our types, queries and mutations to singleton it fixed all our issues. Thanks again for the assistance 🙌
@Heuts I close this but you may ask additional questions if any.
Yes. You’re getting concurrency issues: every time a request comes in, the schema initializes all of the graph types, creating links between them all. If another request comes in at the same time, it is initializing those same graph type instances again, and concurrency problems can cause internal lists to contain duplicate entries or be missing entries. You probably don’t see it in dev because you don’t typically have two schemas initializing at the same time.
https://github.com/graphql/graphql-js/blob/15040d02eb3c5ce2122c9329d26df5cde5ff5b3f/src/type/validate.ts#L466