Mutations
type Mutation {
addRating(title: String, stars: Int):Rating
}
type Rating {
avgStars: Float
}@DgsComponent
public class RatingMutation {
@DgsData(parentType = "Mutation", field = "addRating")
public Rating addRating(DataFetchingEnvironment dataFetchingEnvironment) {
int stars = dataFetchingEnvironment.getArgument("stars");
if(stars < 1) {
throw new IllegalArgumentException("Stars must be 1-5");
}
String title = dataFetchingEnvironment.getArgument("title");
System.out.println("Rated " + title + " with " + stars + " stars") ;
return new Rating(stars);
}
}输入类型
作为 data fetcher 方法的输入参数
Kotlin 数据类型
最后更新于