Graphql接受用户定义对象列表

问题描述:

我有一个要求,我必须接受对象列表。Graphql接受用户定义对象列表

的突变种类的方法是这样的

@GraphQLMutation //1 
    public void ack(@GraphQLInputField List<PingEntity> pingEntityList) { //2 
     log.info("Handling ack calls.");   
     pingEntityRepository.savePingEntityList(pingEntityList); 
    } 

PingEntity看起来像这样

@Data 
//@Document(collection="pingdatastore") 
@AllArgsConstructor 
@NoArgsConstructor 
@JsonIgnoreProperties(ignoreUnknown = true) 
public class PingEntity { 

    private String id; 

    @JsonProperty("action") 
    private String action; 

    @JsonProperty("message") 
    private String message; 

    @JsonProperty("timestamp") 
    private Long timestamp; 

    @JsonProperty("transactionId") 
    private String transactionId; 

    @JsonProperty("type") 
    private Integer type; 

    private String imei; 

} 

我的查询看起来像这样

mutation ack { 
    ack(pingEntityList: [{action: "KEEP-ALIVE2", message: "Keep alive message at regular intervals", timestamp: 1462747047}]) { 
    id 
    } 
} 

我得到了这样的错误:

"data": null, 
    "errors": [ 
    { 
     "validationErrorType": "SubSelectionNotAllowed", 
     "message": "Validation error of type SubSelectionNotAllowed: Sub selection not allowed on leaf type Boolean", 
     "locations": [ 
     { 
      "line": 2, 
      "column": 3 
     } 
     ], 
     "errorType": "ValidationError" 
    } 
    ] 
} 

我试过给出不同的注释。我不能够提前:)来解决这个问题..需要帮助在这个问题上

感谢

的问题似乎是,你ack方法返回void其被映射到boolean中,对于没有的更好的选择。由于boolean是一个简单的标量,因此您无法从中选择任何内容,而您正试图在查询中选择一个id

如果您要更改ack方法以返回保存的List<PingEntity>,您会得到您想要的行为。

但是......更重要的是,你使用的是什么库,作为注解我看到(@GraphQLInputField)在你的代码是从graphql的Java不(如graphql-Java本身不提供任何注解),也没有任何我认识的图书馆。

它似乎来自一个非常古老的,从未公开发布的graphql-spqr版本。如果确实如此,那么您绝对需要更新到最新版本,因为您似乎使用的版本最好是alpha版本。