[英]How to get a schema file in graphql using spqr-spring-boot-starter?
[英]How to get the generated scheme file .graphqls using 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;
}
}
服务等级:
class UserService {
@GraphQLQuery(name = "user")
public User getById(@GraphQLArgument(name = "id") Integer id) {
...
}
}
预期输出:
type User {
id: Int!
name: String!
registrationDate: String
}
Query{
user(Int):User
}
这实际上不是SPQR特定的。 所有必需的类由graphql-java本身提供:
new SchemaPrinter().print(schema);
要获得更详细的输出(带有标量,自省类型等),请为打印机提供选项:
new SchemaPrinter(
// Tweak the options accordingly
SchemaPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeIntrospectionTypes(true)
.includeSchemaDefintion(true)
).print(schema);
在应用程序属性中添加graphql.spqr.gui.enabled=true
启用gui(playground)
。 可以从 GUI 浏览和下载架构和文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.