猿问

如何使用 SPQR 获取生成的方案文件 .graphqls?

我真的很喜欢 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 

}


慕哥6287543
浏览 162回答 2
2回答

aluckdog

这并不是 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);
随时随地看视频慕课网APP

相关分类

Java
我要回答