All Projects → saturn4er → proto2gql

saturn4er / proto2gql

Licence: MIT license
The project has been migrated to https://github.com/EGT-Ukraine/go2gql.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to proto2gql

go2gql
graphql-go schema generator by proto files
Stars: ✭ 33 (+57.14%)
Mutual labels:  schema, protobuf, api-gateway, protoc, codegenerator, proto, graphql-go
Protobuf Dynamic
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
Stars: ✭ 186 (+785.71%)
Mutual labels:  schema, protobuf, protoc
Pb And K
Kotlin Code Generator and Runtime for Protocol Buffers
Stars: ✭ 137 (+552.38%)
Mutual labels:  protobuf, protoc
Goprotowrap
A package-at-a-time wrapper for protoc, for generating Go protobuf code.
Stars: ✭ 147 (+600%)
Mutual labels:  protobuf, protoc
Protobuf Convert
Macros for convenient serialization of Rust data structures into/from Protocol Buffers 3
Stars: ✭ 22 (+4.76%)
Mutual labels:  schema, protobuf
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+248971.43%)
Mutual labels:  protobuf, protoc
Protodot
transforming your .proto files into .dot files (and .svg, .png if you happen to have graphviz installed)
Stars: ✭ 107 (+409.52%)
Mutual labels:  protobuf, protoc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+880.95%)
Mutual labels:  protobuf, protoc
Protobuf
A pure Elixir implementation of Google Protobuf
Stars: ✭ 442 (+2004.76%)
Mutual labels:  protobuf, protoc
protokit
A starter kit for building protoc plugins. Rather than write your own, you can just use an existing one.
Stars: ✭ 69 (+228.57%)
Mutual labels:  protobuf, protoc
protobuf-maven-plugin
Maven Plugin that executes the Protocol Buffers (protoc) compiler
Stars: ✭ 204 (+871.43%)
Mutual labels:  protobuf, protoc
Protoc Jar
Protocol Buffers protobuf compiler - multi-platform executable protoc JAR and API
Stars: ✭ 103 (+390.48%)
Mutual labels:  protobuf, protoc
Protobuf Swift
Google ProtocolBuffers for Apple Swift
Stars: ✭ 925 (+4304.76%)
Mutual labels:  protobuf, protoc
Protoc Gen Doc
Documentation generator plugin for Google Protocol Buffers
Stars: ✭ 1,792 (+8433.33%)
Mutual labels:  protobuf, protoc
Prototool
Your Swiss Army Knife for Protocol Buffers
Stars: ✭ 4,932 (+23385.71%)
Mutual labels:  protobuf, protoc
Protoc Jar Maven Plugin
Protocol Buffers protobuf maven plugin - based on protoc-jar multi-platform executable protoc JAR
Stars: ✭ 177 (+742.86%)
Mutual labels:  protobuf, protoc
Protoc Gen Gotemplate
📂 generic protocol generator based on golang's text/template (grpc/protobuf)
Stars: ✭ 284 (+1252.38%)
Mutual labels:  protobuf, protoc
Protolock
Protocol Buffer companion tool. Track your .proto files and prevent changes to messages and services which impact API compatibility.
Stars: ✭ 394 (+1776.19%)
Mutual labels:  protobuf, protoc
Schema Registry
Confluent Schema Registry for Kafka
Stars: ✭ 1,647 (+7742.86%)
Mutual labels:  schema, protobuf
metastore
A protobuf schema registry on steroids. It will keep track of the contracts throughout your organization, making sure no contract is broken.
Stars: ✭ 43 (+104.76%)
Mutual labels:  schema, protobuf

proto2gql

The project has been migrated to https://github.com/EGT-Ukraine/go2gql.

Tool, which generates graphql-go schema for .proto file.

Installation

$ go get github.com/saturn4er/proto2gql/cmd/proto2gql

Usage

To generate GraphQL fields by .proto

$ ./proto2gql

Generation process

Generation process

Config example

paths:                         # path, where parser will search for imports
  - "${GOPATH}/src/"     
generate_tracer: true          # if true, generated code will trace  all functions calls

output_package: "graphql"      # Common Golang package for generated files 
output_path: "./out"           # Path, where generator will put generated files

imports:                       # .proto files imports settings
  output_package: "imports"    # Golang package name for generated imports
  output_path: "./out/imports" # Path, where generator will put generated imports files
  aliases:                     # Global aliases for imports. 
    google/protobuf/timestamp.proto:  "github.com/gogo/protobuf/protobuf/google/protobuf/timestamp.proto"
  settings:
    "${GOPATH}src/github.com/gogo/protobuf/protobuf/google/protobuf/timestamp.proto":
      go_package: "github.com/gogo/protobuf/types"   # golang package, of generated .proto file
      gql_enums_prefix: "TS"                         # prefix, which will be added to all generated GraphQL Enums
      gql_messages_prefix: "TS"                      # prefix, which will be added to all generated GraphQL Messages(including maps)
       

protos:
  - proto_path: "./example/example.proto"           # path to .proto file              
    output_path: "./schema/example"                 # path, where generator will put generated file
    output_package: "example"                       # Golang package for generated file
    paths:                                          # path, where parser will search for imports.  
      - "${GOPATH}/src/github.com/saturn4er/proto2gql/example/"
    gql_messages_prefix: "Example"                  # prefix, which will be added to all generated GraphQL Messages(including maps)
    gql_enums_prefix: "Example"                     # prefix, which will be added to all generated GraphQL Enums
    imports_aliases:                                # imports aliases
      google/protobuf/timestamp.proto:  "github.com/google/protobuf/google/protobuf/timestamp.proto"
    services:             
      ServiceExample:
        alias: "NonServiceExample"                  # service name alias
        methods:  
          queryMethod:                              
            alias: "newQueryMethod"                 # method name alias
            request_type: "QUERY"                   # GraphQL query type (QUERY|MUTATION)
    messages:
      MessageName:
        error_field: "errors"                       # recognize this field as payload error. You can access it in interceptors
        fields:
          message_field: {context_key: "ctx_field_key"}  # Resolver, will try to fetch this field from context instead of fetching it from arguments
          
schemas:  
  - name: "SomeSchema"                  # Schema name
    output_path: "./out/schema.go"      # Where generator will put fabric for this schema
    output_package: "test_schema"       # Go package name for schema file
    queries:
      type: "SERVICE"                   
      proto: "Example"
      service: "ServiceExample"
      filter_fields:
        - "MsgsWithEpmty"
      exclude_fields:
        - "excludedField"

    mutations:
      type: "OBJECT"
      fields:
        - field: "nested_example_mutation"
          type: "OBJECT"
          object_name: "NestedExampleMutation"
          fields:
            - field: "ExampleService"
              type: "SERVICE"
              object_name: "ServiceExampleMutations"
              proto: "Example"
              service: "ServiceExample"
              filter_fields:
                - "MsgsWithEpmty"
 

Interceptors

There's two types of Interceptors. The first one can do some logic while parsing GraphQL arguments into request message and the second one, which intercept GRPC call. Here's an example, how to work with it

package main

import (
	"fmt"
	
	"google.golang.org/grpc"
	"github.com/saturn4er/proto2gql/api/interceptors"
)
	

func main(){
    ih := interceptors.InterceptorHandler{}
    ih.OnResolveArgs(func(ctx *interceptors.Context, next interceptors.ResolveArgsInvoker) (result interface{}, err error) {
    	fmt.Println("Before resolving request message")
    	req, err := next()
    	fmt.Println("After resolving request message")
    	return req, err
    })
    ih.OnCall(func(ctx *interceptors.Context, req interface{}, next interceptors.CallMethodInvoker, opts ...grpc.CallOption) (result interface{}, err error) {
        fmt.Println("Before GRPC Call")
        res, err := next(req, opts...)
        fmt.Println("After GRPC Call")
        return res, err
    })
    // queriesFields := GetSomeServiceQueriesFields(someClient, ih)
    // create other schema...
}

How generated code works

workflow

Todo

  • fields generation
  • schema generation
  • bytes fields
  • test resolvers
  • other languages support ???
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].