Hotchocolate: No compatible constructor found for input type xxx

Created on 13 Jan 2020  ยท  10Comments  ยท  Source: ChilliCream/hotchocolate

Since updating from 10.2.0 during startup when adding my types I get an exception No compatible constructor found for input type: MyUnderlyingType There is no constructor on the type as it just a POCO. I tried commenting out parts to try and locate something more specific but I haven't managed to track it down other than reverting back to 10.2.0 makes it go away.

โ“ question

All 10 comments

Ok It seems to occur because I have a List property on my POCO with no set accessor. If I add a set accessor to the property or when configuring the InputObject to explicitly tell the descriptor to ignore the then it works.

Ideally I just want to change the list by using the Add() and Remove() methods. Is there a way I can do this without ignoring the property or adding a set accessor?

But what would we do when the list is set to null?

BTW, you also can let us pass your read-only props into a constructor.

public class Foo 
{
    public Foo(Bar bar) 
    {
        Bar = bar;
    }

    public Bar Bar { get; }
}

I will close this issue. We will revisit the deserialization again in march after we have the new execution engine in.

Is there a way to work around this? E.g. if the type I have as an input type type is in a library I am unable to change, can I specify a way to construct each element, or ignore the property that I know has the wrong accessors?

For the library I am working with there is a class with one property which has a protected setter, I want to be able to ignore this as I cannot change the types library.

If you ignore the property it will not be taken into account. You can either ignore the property with the fluent API or with the GraphQLIgnore Attribute.

In your case I know only the fluent API will work since it is from an external lib.

The question here is why bind a field for input serialization if it cannot be accessed by the serializer?

public class FooInputType : InputType<Foo> 
{
    protected override void Configure(IInputObjectTypeDescriptor<Foo> descriptor) 
    {
        descriptor.Ignore(t => t.Prop);
    }
}

@michaelstaib we already discussed this on slack. @dillanmann did try to ignore it with Ignore but apparently it did not work.

Strange, we will have to write a test for this and verify that this is true and then look what is causing the issue. Anybody wants to do a pr?

Test would go here:
https://github.com/ChilliCream/hotchocolate/blob/master/src/HotChocolate/Core/test/Types.Tests/Types/InputObjectTypeTests.cs

@michaelstaib / @PascalSenn i am running into a similar issue with an external library, I will add the code here, but i am first going to try the fluent API ignore, there are some calculated properties on the class

  • Update 09/19/2020 creating an Input type ignoring the properties with no setters or creating a different input type worked

Can you pinpoint what your issue is?

FYI I believe I managed to get this working, but the way that I had to ignore it was different than what you specified. I can't remember the exact details, I'll check tomorrow to see what I did for you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lTimeless picture lTimeless  ยท  5Comments

acelot picture acelot  ยท  4Comments

nigel-sampson picture nigel-sampson  ยท  5Comments

IKolosynskyi picture IKolosynskyi  ยท  3Comments

benmccallum picture benmccallum  ยท  3Comments