有没有办法从Protobuf自动生成GraphQL模式?

huangapple 未分类评论46阅读模式
英文:

Is there any way auto generate graphql schema from protobuf?

问题

我正在使用Spring Boot开发GraphQL。由于数据结构已在Protobuf中声明,我尝试了将其用于代码中。这是我的代码示例。

@Service
public class Query implements GraphQLQueryResolver {

    public MyProto getMyProto() {
       /**/
    }

}

我希望将代码做成像上面的结构。为了做到这一点,我将工作分为两个部分。

    1. 由于“proto文件”可以转换为Java类,我将使用此类作为返回类型。

第二部分是主要问题。

    1. 同样需要架构。起初,我尝试手动编写架构。但是,proto文件的实际大小约为1000行。因此,我想知道是否有任何方法可以将“proto文件”转换为“graphqls文件”。
英文:

I am developing springboot with GraphQL. Since the data structure is already declared within Protobuf, I tried to use it. This is example of my code.

@Service
public class Query implements GraphQLQueryResolver {

    public MyProto getMyProto() {
       /**/
    }

}

I want make code like upper structure. To to this, I divided job into 2 sections.

    1. Since ".proto file" can be converted to java class, I will use this class as return type.

And The second section is a main matter. <br>

    1. Also Schema is required. At first, I tried to code schema with my hand. But, the real size of proto is about 1000 lines. So, I want to know Is there any way to convert ".proto file" to ".graphqls file".

答案1

得分: 0

这是一种方法。我正在使用一个用于此目的的 protoc 插件:go-proto-gql

它非常简单易用,例如:

protoc --gql_out=paths=source_relative:. -I=. ./*.proto

希望这对你也有效。

英文:

There is a way. I am using the a protoc plugin for that purpose: go-proto-gql

It is fairly simple to be used, for example:

protoc --gql_out=paths=source_relative:. -I=. ./*.proto

Hope this is working for you as well.

huangapple
  • 本文由 发表于 2020年7月24日 13:07:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/63067192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定