graphql-dotnet: Type is abstract and can not be used to construct objects from dictionary values. Please register a conversion within the ValueConverter or for input graph types override ParseDictionary method
I have an error message that I cannot figure out. We are upgrading our .NET Console Apps (used as APIs) from GraphQL 2.4.0 using .NET Core 3.1 and .NET Standard 2.1 helper projects to GraphQL 7.7.2 with .NET 8. We also went from AutoMapper 9 to 12.
Originally we tried using the GraphQL documentation at https://graphql-dotnet.github.io/docs/migrations/ to go from v2 to v3 then v3 to v4 then v4 to v5 then v5 to v7. We punted that idea and just went all in from v2 to v7. We are in a state where our GraphQL Queries are working well but our Mutations are not.
Summary
We are using a Mutation for Inserts/Updates and our Inserts/Updates but we are popping a 400 error with the InnerException message of: “Type ‘IUser’ is abstract and can not be used to construct objects from dictionary values. Please register a conversion within the ValueConverter or for input graph types override ParseDictionary method.”
We googled the error message and I don’t get much. I do see that part of the error is shown on https://graphql-dotnet.github.io/docs/migrations/migration4/ but I’ll be honest that I’m new to GraphQL and I haven’t touched .NET in 5 years. If my answer is on the migration4 link, I wouldn’t know.
I don’t know what the error is saying. I thought maybe there was a problem with my Field statements. We had Field("isActive", x => x.IsActive, type: typeof(BooleanGraphType)); but changed to Field<BooleanGraphType>("IsActive"); thinking we were on to something. But, we have the same error.
Any pointers?
Thanks!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (8 by maintainers)
@Shane32 DUDE! MY DUDE! You saved me hours, at least!
I must have some sort of Frankenstein input graph type even though not by specific name. Either way, that override satisfied the error. I would have never would have guessed the ParseDictionary signature let alone know to return value. The docs went clear over my head, too.
I don’t have an error and my data seems to have saved. I was too excited to even check the DB. I don’t have errors!
Thank you so much!
How the fields are configured have not really changed internally even though the recommended syntax is a bit different now. If you want to post the before/after, I can confirm that it is being configured the same.
What’s different (as it relates to your original issue here), is that the inputs are converted to their CLR types during validation rather than during execution. This helps catch parsing errors before execution begins. However, the GraphQL.NET engine has to guess at the
TinGetArgument<T>, which it does so based on theTinInputObjectGraphType<T>.For example:
The issue would actually apply to both
InputObjectGraphType<T>as well asAutoRegisteringInputObjectGraphType<T>. However,InputObjectGraphTypedoes not callToObject(since it does not know whatTis) and so it would be immune to this problem.Note that the v8 beta compiles the
ToObjectcode during schema initialization for faster execution and would notice the error then. But not so for v7.