简体   繁体   English

Graphql null 指针异常即使不是 null

[英]Graphql null pointer exception even though it is not null

I am trying to create a player using createPlayer mutation.我正在尝试使用 createPlayer 突变创建一个播放器。 I enter the parameters for playerDTO but I get a null pointer exception我输入了 playerDTO 的参数,但我得到了 null 指针异常

Cannot invoke "com.example.basketballteam.dto.PlayerDTO.getName()" because "playerdto" is null

Here is my mutation:这是我的突变:

input PlayerDTO{
    name:String!,
    lastName:String!,
    position:Position!
}
type Mutation{
    createPlayer(plyr: PlayerDTO):Player
    deletePlayer(id: ID):Boolean
    addPlayerToTeam(id:ID,tid:ID):Player
}

here is my controller这是我的 controller

  @MutationMapping
    public Player createPlayer(@Argument PlayerDTO playerdto){
        return playerRepository.save(playerMapper.ToEntity(playerdto));
    }

and this is my mapper:这是我的映射器:

  public Player ToEntity(PlayerDTO playerdto){
        Player player = new Player();
        player.setName(playerdto.getName());
        player.setLastName(playerdto.getLastName());
        player.setPosition(playerdto.getPosition());

        return player;
    }

The name in the graphql schema (type Mutation) must be the same as your data transfer object parameter in your controller graphql 模式(Mutation 类型)中的名称必须与 controller 中的数据传输 object 参数相同

input PlayerDTO{
    name:String!,
    lastName:String!,
    position:Position!
}

type Mutation{
    createPlayer(player: PlayerDTO):Player
    deletePlayer(id: ID):Boolean
    addPlayerToTeam(id:ID,tid:ID):Player
}

With this controller it should work有了这个 controller 它应该可以工作

  @MutationMapping
  public Player createPlayer(@Argument PlayerDTO player){
    return playerRepository.save(playerMapper.ToEntity(player));
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空指针异常,即使照片在那里 - null pointer exception even though photo there 即使没有recyclerview,Recyclerview onMeasure Java空指针异常 - Recyclerview onMeasure java null pointer exception even though there is no recyclerview JComboBox 触发 null 指针,即使它没有被调用? - JComboBox triggering null pointer even though it was not called on? Freemarker null异常,即使先检查它也是如此 - Freemarker null exception even though checking for it first 为什么我得到空指针异常,即使println有值显示? - Why I am getting null pointer exception even though there is value show when println? 即使图像在我指定的路径中,图像图标也返回空指针异常 - Image Icon is returning null pointer exception even though the image is there in the path I specified 从HashMap检索时返回null指针异常,即使containsKey()返回true - null pointer exception when retrieving from HashMap even though containsKey() returns true 空指针异常,即使在初始化数组时也是如此 - Null Pointer Exception even when array is initialized 即使输入值,文本字段也将出现空指针错误 - null pointer error at textfield even though value is entered 即使定义了适配器,RecyclerView 也会为 setAdapter 抛出空指针 - RecyclerView throws null pointer for setAdapter even though the adapter is defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM