• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

danielvladco/go-proto-gql: Protobuf plugins for generating graphql schema and go ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

danielvladco/go-proto-gql

开源软件地址(OpenSource Url):

https://github.com/danielvladco/go-proto-gql

开源编程语言(OpenSource Language):

Go 97.7%

开源软件介绍(OpenSource Introduction):

codecov

Protoc plugins for generating graphql schema and go graphql code

If you use micro-service architecture with grpc for back-end and graphql api gateway for front-end, you will find yourself repeating a lot of code for translating from one transport layer to another (which many times may be a source of bugs)

This repository aims to simplify working with grpc trough protocol buffers and graphql by generating code.

Install:

go install github.com/danielvladco/go-proto-gql/protoc-gen-gql
go install github.com/danielvladco/go-proto-gql/protoc-gen-gogql

Usage Examples:

The protoc compiler expects to find plugins named proto-gen-<PLUGIN_NAME> on the execution $PATH. So first:

export PATH=${PATH}:${GOPATH}/bin

--gql_out plugin will generate graphql files with extension .graphqls rather than go code which means it can be further used for any other language or framework.

Example:

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

If you still want to generate go source code instead of graphql then use http://github.com/99designs/gqlgen plugin, and map all the generated go types with all the generated graphql types. Luckily --gqlgencfg_out plugin does exactly this.


--gogql_out plugin generates methods for implementing github.com/99designs/gqlgen/graphql.Marshaler and github.com/99designs/gqlgen/graphql.Unmarshaler interfaces. Now proto enums, oneofs and maps will work fine with graphql.

This plugin also creates convenience methods that will implement generated by the gqlgen MutationResolver and QueryResolver interfaces.

Example:

protoc --gogql_out=gogoimport=false,paths=source_relative:. -I=. -I=./example/ ./example/*.proto

See /example folder for more examples.

Gateway (alpha)

A unified gateway is also possible. Right now a gateway can be spawn up pointing to a list of grpc endpoints (grpc reflection must be enabled on the grpc servers). The gateway will query the servers for protobuf descriptors and generate a graphql schema abstract tree. The requests to the gateway will be transformed on the fly to grpc servers without any additional code generation or writing any code at all. See examples/gateway for usage more info.

Community:

Will be very glad for any contributions so feel free to create issues, forks and PRs.

License:

go-proto-gql is released under the Apache 2.0 license. See the LICENSE file for details.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap