1

Let's say I have

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="trade_id")
    int tradeId;

When I query this from the database, I will want to get the tradeId. However, when performing a Create, obviously I won't have the tradeId, since the Database is going to generate it when I insert it.

input TradeInput {
  tradeId: Int!
...

But the schema SPQR is generating for me is setting this field to Not Null, however.

So my question is, how can prevent this field from automatically coming up as Not Null, so I won't have to send it down on Creates, but can retrieve it.

Steve
  • 4,457
  • 12
  • 48
  • 89

1 Answers1

1

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
kaqqao
  • 12,984
  • 10
  • 64
  • 118
  • Thank you! That makes sense about int/Integer. Btw, any reason you editted your reply to not include the suggestion to use 0.0.6? When I try it, I get Failed to introspect Class [io.leangen.graphql.spqr.spring.web.HttpExecutor] from ClassLoader. Is that a known issue/is that why you retracted your recommendation? – Steve Aug 30 '21 at 14:42
  • @Steve Huh, no. Only because you didn't mention the version you're using here, so I thought it would be confusing to mention it out of the blue. Never heard of the issue you mention before... If you don't figure it out quickly, please open an issue with a minimal example replicating it. – kaqqao Aug 30 '21 at 23:09