我将GraphQL SPQR与实体一起使用
@Entity
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
@GraphQLNonNull
@GraphQLQuery(name = "a", description = "Any field")
private String a;
// Getters and Setters
}
和服务
@Service
@Transactional
public class MyService {
@Autowired
private MyRepository myRepository;
@GraphQLMutation(name = "createEntity")
public MyEntity createEntity(@GraphQLArgument(name = "entity") MyEntity entity) {
myRepository.save(entity);
return entity;
}
}
在 GraphiQL 中,我可以设置id
:
mutation {
createEntity(entity: {
id: "11111111-2222-3333-4444-555555555555"
a: "any value"
}) {
id
}
}
但是id
不应使用户可编辑,因为它将被数据库覆盖。它只应在查询时显示。我尝试并添加了@GraphQLIgnore
,但id
显示的都是一样的。
如何隐藏id
at 创建?