功能介绍
graphql-java
提供了Mutations
类型支持数据更新
NGS Mutations
类型定义
代码语言:yaml复制type Mutation {
addActor(actor: SubmitActor!): Actor
}
type Subscription {
actorAdded: Actor
}
input SubmitActor {
firstName: String!
lastName: String!
}
SubmitActor类型可以交给代码生成器自动生成
类型转换器
代码语言:java复制@Mapper(componentModel = SPRING)
public interface ActorAssembler {
Actor convert(SubmitActor submit);
}
定义解析器
代码语言:java复制 @DgsMutation
public Actor addActor(@InputArgument SubmitActor actor) {
Actor actorEntity = actorAssembler.convert(actor);
actorEntity.setActorId(10);
actorEntity.setLastUpdate(new Date());
return actorEntity;
}
测试
访问http://localhost:8080/graphiql即可看到在线查询页面