4

我真的很喜欢 SPQR 可以轻松地将与现有系统集成的方式,我唯一想看到的是.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 
}
4

2 回答 2

9

This is not really SPQR specific. All the needed classes are provided by graphql-java itself:

new SchemaPrinter().print(schema);

To get a more detailed output (with scalars, introspection types etc), provide the options to the printer:

new SchemaPrinter(
                  // Tweak the options accordingly
                  SchemaPrinter.Options.defaultOptions()
                          .includeScalarTypes(true)
                          .includeExtendedScalarTypes(true)
                          .includeIntrospectionTypes(true)
                          .includeSchemaDefintion(true)
            ).print(schema);
于 2018-09-04T16:49:46.560 回答
0

添加graphql.spqr.gui.enabled=true应用程序属性启用gui(playground). 可以从 GUI 浏览和下载模式和文档。

于 2021-08-03T03:42:07.027 回答