smallrye-graphql
smallrye-graphql copied to clipboard
GraphQL Mutation exceptions when no setters are present.
Hello,
With Quarkus GraphQL, I am facing couple of exceptions with mutations when setters are not present in the model class. I made a small reproducer for this, which is available at https://github.com/zbhavyai/quarkus-graphql-nosetters-reproducer.
To explain, the Film
class has no setters. The REST endpoints to add a Film
works fine. The GraphQL mutations however throw exception - Cannot create instance of a class. No default constructor found.
When I add a default constructor, InvalidSchemaException
is thrown at build time.
The exceptions faced might be somewhat related to https://github.com/smallrye/smallrye-graphql/issues/1342, but I am not sure if the actual issue is related at all.
So, my question is - why exactly are setters required? If REST works fine without them, shouldn't GraphQL too? Is it bug or GraphQL limitation?
Thanks in advance.
To be able to do a mutation you are going to need setters. Why do you not have setters ?
Because, I am building a GraphQL wrapper on an existing service that doesn't have setters. The REST wrapper on that works without any issues, so I wondered why GraphQL doesn't work.
Is there any particular reason why GraphQL mutation need setters? IMHO the parameterized constructors should be enough to create the object using the Jackson deserialization.
Thanks.
If I remember correctly, the quarkus version still uses jsonb. If you don't have setters, you need to do something like this for the server input objects https://github.com/smallrye/smallrye-graphql/blob/3f7a7ab79ade1b049a73ff4a0e66128d171ee7d3/server/integration-tests-jdk16/src/test/java/io/smallrye/graphql/tests/records/RecordTest.java#L103
@robp94 Yeah this one works after I update my constructor with @JsonbCreator
. Thanks for letting this know!
Want to check, can we have Jackson support for Quarkus GraphQL?
What do you mean by Jackson support?
To put it simply, expecting GraphQL mutations to work with @JsonCreater
annotated constructor rather than to rely on @JsonbCreator
as robp94 suggested.
Should be possible. Let's leave this open and we can look at it at some point. Or you can do a PR if you are keen.
I think this should work with com.fasterxml.jackson.annotation.JsonCreator
( at least I see the code for it: https://github.com/smallrye/smallrye-graphql/blob/a7216b53ea69dda57fcc2d33766b6caf9b44b615/common/schema-builder/src/main/java/io/smallrye/graphql/schema/Annotations.java#L615)
Not sure if you meant to do it differently (posted reproducer does uses @JsonCreator
), but I see the exact same error. Tried with quarkus version 2.11.1.Final
. Again, @JsonbCreator
works but not @JsonCreator
.
Yes initially I thought we don't support it, but we do, as the annotations are there, so this is a bug