I am looking a way to pass an Int array to a GraphQL mutation.

I am not sure what I am doing incorrect here.I am getting this error:

Field error in object 'hepatitisLabConditionGroupInput' on field '$.conditionIds': rejected value [null]; codes [unknownType.hepatitisLabConditionGroupInput,unknownType]; arguments []; default message [Unknown Collection element type]

I am able to pass a single Int value, if I change from [Int] to just Int.

I tried looking online, I think I am passing the Int array correct way. Like here:

conditionIds: [77,78]

Can you please let me know what am I doing incorrectly here?

Here is my GraphQL endpoint:

mutation{
  saveHepatitisLabConditionGroup(hepatitisLabConditionGroupInput:{
    groupId: 100
    groupName: "Test 1"
    conditionIds:   [77,78]
  })
}

Here is the input and mutation:

input HepatitisLabConditionGroupInput{
    groupId: Int
    groupName: String!
    conditionIds: [Int]
}

extend type Mutation{
    saveHepatitisLabConditionGroup (hepatitisLabConditionGroupInput: HepatitisLabConditionGroupInput):Boolean
}

Controller starting line:

  @MutationMapping
    Boolean saveHepatitisLabConditionGroup(@Argument HepatitisLabConditionGroupInput hepatitisLabConditionGroupInput) {

Here is my DTO:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class HepatitisLabConditionGroupInput {
    Long groupId;
    String groupName;
    Long[] conditionIds;
}
1

There are 1 best solutions below

1
shortduck On

I was able to resolve this issue. The fix was to have List , instead of Int [].

So the above code stats as it, with the exception as:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class HepatitisLabConditionGroupInput {
    Long groupId;
    String groupName;
    List <Long> conditionIds; 
    // This is invalid: Long [] conditionIds;
}