conventions: After updating to 7.0.0, problems with executing operations that include union types
GraphQL 7.1.1 GraphQL.NewtonsoftJson 7.0.1 GraphQL.Server.Transports.AspNetCore 7.1.1 GraphQL.Conventions 7.0.0
After Updating to the newest Version and after adjusting for the breaking changes by reading the migration guides, I still have a problem with Union types that I’m not able to fix.
When I try to run a query that returns an union type, the ExecutionResult contains this error:
Unable to cast object of type ‘GraphQL.Conventions.Adapters.Types.UnionGraphType`1[GqlExampleResult]’ to type ‘GraphQL.Types.IComplexGraphType’.
The mentioned type looks like this:
[Name("ExampleResult")]
public class GqlExampleResult : Union<GqlExampleInformation, GqlErrorInfo>
{
public GqlExampleResult(GqlExampleInformation information)
{
base.Instance = information;
}
public GqlExampleResult(GqlErrorInfo gqlErrorInfo)
{
base.Instance = gqlErrorInfo;
}
}
Second problem: When I use a different query, it works only once, the second execution fails with:
Error executing document. This graph type ‘X’ has already been initialized. Make sure that you do not use the same instance of a graph type in multiple schemas. It may be so if you registered this graph type as singleton; see https://graphql-dotnet.github.io/docs/getting-started/dependency-injection/ for more info.
X in this case is a possible type of another Union type that was not even used in this query. Edit: This second error seems to have been some configuration mistake that I can’t reproduce anymore.
Are these some obvious errors for you, or do I need to dig out more debug data?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (13 by maintainers)
This bug is confirmed to be a GraphQL.NET issue and will be tracked here:
No changes are necessary in this repo. Once the issue is fixed in GraphQL.NET, simply reference the updated nuget package and the issue should be resolved. Please reopen this issue if that is not the case.