如何使用SPQR获取生成的方案文件.graphqls? [英] How to get the generated scheme file .graphqls using SPQR?

查看:216
本文介绍了如何使用SPQR获取生成的方案文件.graphqls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢SPQR易于集成的方式在现有系统上,我唯一想看的是 .graphqls 文件,这样我就可以了解有关GraphQL语法的更多信息.

I really like the way SPQR makes easy to integrate graphql with an existing system, the only thing I'd like to see is the .graphqls file so I can learn more on GraphQL Syntax.

是否有一种方法可以从集成了SPQR注释的现有代码中生成方案文件?

Is there a way to generate the scheme file from an existing code with SPQR annotations integrated?

要提供一些代码,我们使用 GitHub网站

To provide some code let's use the same code from the GitHub site

实体:

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本身提供:

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);

这篇关于如何使用SPQR获取生成的方案文件.graphqls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆