Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID field needs to be nullable, at least on Input #409

Open
stevedefazio opened this issue Aug 27, 2021 · 1 comment
Open

ID field needs to be nullable, at least on Input #409

stevedefazio opened this issue Aug 27, 2021 · 1 comment

Comments

@stevedefazio
Copy link

(Also posted on StackOverflow: https://stackoverflow.com/questions/68957980/how-to-handle-identity-fields-in-graphql-spqr)

I have a field as follows:

@id @GeneratedValue(strategy=GenerationType.IDENTITY)
@JsonProperty
@column(name="trade_id")
int tradeId;

Somehow, SPQR is concluding that this field should not Not Null, even though I am not explicitly declaring it as such.

input TradeInput {
tradeId: Int!

The trouble is, when I create a Trade object, the tradeID value is going to be generated by the database. So I never want to pass one in. However, I don't want to ignore the field entirely, because when I'm retrieving Trade objects, I want to include the ID.

Is there a way to do this? I'm using graphql-spqr-spring-boot-starter v 0.0.4

@kaqqao
Copy link
Member

kaqqao commented Aug 28, 2021

Answered on StackOveflow. Copying here for posterity:

An int simply can not be null. But you have a few options:

  • Turn it into an ID scalar type (using @GraphQLId) instead of an Int
  • Give it a default value via @GraphQLInputField
  • Use Integer instead of int, as Integer is nullable

Btw, it's highly advised to upgrade to the latest version of the starter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants