graphql-dotnet: v5 Migration problem
System.InvalidOperationException
HResult=0x80131509
Message=Abstract type Character must resolve to an Object type at runtime for field Query.hero with value 'System.Threading.Tasks.Task`1[GraphQL.StarWars.Types.Droid]', received 'null'.
Source=GraphQL
StackTrace:
at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node) in C:\_GITHUB_\graphql-dotnet\src\GraphQL\Execution\ExecutionStrategy.cs:line 620
My test contains
Field<CharacterInterface>(“hero”, resolve: context => data.GetDroidByIdAsync(“3”));
That should be changed in v5 to
FieldAsync<CharacterInterface>(“hero”, resolve: async context => await data.GetDroidByIdAsync(“3”));
“Bug” can be reproduced easily by changing StarWarsQuery.cs line 12.
It was not obvious to me. Code compiles well but throws in runtime. Will we do something to deal with it? Add some kind of check / friendly error message?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (13 by maintainers)
@bp74 Take a look at the upcoming during few hours v7.
When the service starts up, all GraphTypes and all Fields are initialized. Wouldn’t it be possible just the throw an exception on startup, telling the developer that Tasks are no longer supported for Fields? The change (to FieldAsync) is quite easy, the only problem is that it is a breaking change that you don’t recognize until a query runs which accesses a Field which uses a resolver delegate that returns a Task. So when the Field is initialized, you should be able to know that the delegate returns is a Task, then throw an error, Otherwise - guys, you are doing a great job with the library, very much appricate your work!