Giter Site home page Giter Site logo

enosi-rl / go-proto-gql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fresh8gaming/go-proto-gql

0.0 0.0 0.0 4.83 MB

Protobuf plugins for generating graphql schema and golang to graphql bindings. Also supports a graphql gateway (Alpha)

License: Apache License 2.0

Shell 0.65% Go 98.09% Makefile 1.05% Dockerfile 0.21%

go-proto-gql's 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/fresh8gaming/go-proto-gql/protoc-gen-gql
go install github.com/fresh8gaming/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.

go-proto-gql's People

Contributors

danielvladco avatar adam-cv avatar snikch avatar appleboy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.