Rus*_*pez 2 java graphql-java graphql-spqr
我真的很喜欢SPQR轻松地将graphql与现有系统集成的方式,我唯一想看的是.graphqls文件,因此我可以在GraphQL语法上学习更多。
有没有一种方法可以从集成SPQR注释的现有代码中生成方案文件?
为了提供一些代码,让我们使用GitHub站点上的相同代码
实体:
public class User {
private String name;
private Integer id;
private Date registrationDate;
@GraphQLQuery(name = "name", description = "A person's name")
public String getName() {
return name;
}
@GraphQLQuery
public Integer getId() {
return id;
}
@GraphQLQuery(name = "regDate", description = "Date of registration")
public Date getRegistrationDate() {
return registrationDate;
}
}
Run Code Online (Sandbox Code Playgroud)
服务等级:
class UserService {
@GraphQLQuery(name = "user")
public User getById(@GraphQLArgument(name = "id") Integer id) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
预期产量:
type User {
id: Int!
name: String!
registrationDate: String
}
Query{
user(Int):User
}
Run Code Online (Sandbox Code Playgroud)
这实际上不是SPQR特定的。所有必需的类由graphql-java本身提供:
new SchemaPrinter().print(schema);
Run Code Online (Sandbox Code Playgroud)
要获得更详细的输出(带有标量,自省类型等),请为打印机提供选项:
new SchemaPrinter(
// Tweak the options accordingly
SchemaPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeIntrospectionTypes(true)
.includeSchemaDefintion(true)
).print(schema);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
720 次 |
| 最近记录: |