gql

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

Go protoc plugin generating graphql schema and graphql resolvers code

The repository aims to simplify working with grpc trough protocol buffers and graphql by generating code. Document here about how to use the generated code: https://github.com/vektah/gqlgen

Given plugins generates boilerplate code that is needed to connect graphql resolvers with grpc services. If you use micro-service architecture with grpc and with graphql api gateway for frontend 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)

Install:

go get github.com/danielvladco/go-proto-gql
cd ${GOPATH}/src/github.com/danielvladco/go-proto-gql/protoc-gen-gogql && go install
cd ${GOPATH}/src/github.com/danielvladco/go-proto-gql/protoc-gen-gogqlenum && go install

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

Add --gogqlenum_out plugin to your protoc code generation comamnd run to generate enum marshal/unmarshal interfaces

NOTE: generate code with --gogo_out rather than --go_out

protoc --gogqlenum_out=. \
    --gogo_out=. \
    --proto_path=${GOPATH}/src/github.com/gogo/protobuf/protobuf \
    --proto_path=${GOPATH}/src/ \
    --proto_path=. \
    account.proto

Import all the proto files for witch you want to generate gql handlers and use call the command like this

protoc --gogql_out=. \
    --proto_path=${GOPATH}/src/github.com/gogo/protobuf/protobuf \
    --proto_path=${GOPATH}/src/ \
    --proto_path=. \
    test.proto

--gogqlenum_out and --gogql_out triggers the protoc-gen-gogqlenum and protoc-gen-gogql plugins to generate required files. This is all the magic here.

See examples folder.

For more documentation inspect code ;)

Dependencies:

github.com/vektah/gqlgen 
github.com/mwitkow/go-proto-validators
github.com/gogo/protobuf

TODO:

  • fix known bugs
  • comments in code and refactor
  • tests
  • gql unions (oneof)
  • gql interfaces (?)
  • gql directives (maybe with proto options)
  • gql input for type field (maybe with proto options)

BUGS:

  • generates output code to the location where you are calling command but not in the out directory as expected (as workaround use this command in the path you want to generate code)

License:

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var E_Field = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.FieldOptions)(nil),
	ExtensionType: (*Field)(nil),
	Field:         65030,
	Name:          "gql.field",
	Tag:           "bytes,65030,opt,name=field",
	Filename:      "gql.proto",
}
View Source
var E_RpcType = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.MethodOptions)(nil),
	ExtensionType: (*Type)(nil),
	Field:         65030,
	Name:          "gql.rpc_type",
	Tag:           "varint,65030,opt,name=rpc_type,json=rpcType,enum=gql.Type",
	Filename:      "gql.proto",
}
View Source
var E_SvcType = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.ServiceOptions)(nil),
	ExtensionType: (*Type)(nil),
	Field:         65030,
	Name:          "gql.svc_type",
	Tag:           "varint,65030,opt,name=svc_type,json=svcType,enum=gql.Type",
	Filename:      "gql.proto",
}
View Source
var Type_name = map[int32]string{
	0: "DEFAULT",
	1: "MUTATION",
	2: "QUERY",
}
View Source
var Type_value = map[string]int32{
	"DEFAULT":  0,
	"MUTATION": 1,
	"QUERY":    2,
}

Functions

This section is empty.

Types

type Field

type Field struct {
	Params               *string  `protobuf:"bytes,1,opt,name=params" json:"params,omitempty"`
	Dirs                 *string  `protobuf:"bytes,2,opt,name=dirs" json:"dirs,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Field) Descriptor

func (*Field) Descriptor() ([]byte, []int)

func (*Field) GetDirs

func (m *Field) GetDirs() string

func (*Field) GetParams

func (m *Field) GetParams() string

func (*Field) ProtoMessage

func (*Field) ProtoMessage()

func (*Field) Reset

func (m *Field) Reset()

func (*Field) String

func (m *Field) String() string

func (*Field) XXX_DiscardUnknown

func (m *Field) XXX_DiscardUnknown()

func (*Field) XXX_Marshal

func (m *Field) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Field) XXX_Merge

func (dst *Field) XXX_Merge(src proto.Message)

func (*Field) XXX_Size

func (m *Field) XXX_Size() int

func (*Field) XXX_Unmarshal

func (m *Field) XXX_Unmarshal(b []byte) error

type Type

type Type int32
const (
	Type_DEFAULT  Type = 0
	Type_MUTATION Type = 1
	Type_QUERY    Type = 2
)

func (Type) Enum

func (x Type) Enum() *Type

func (Type) EnumDescriptor

func (Type) EnumDescriptor() ([]byte, []int)

func (Type) String

func (x Type) String() string

func (*Type) UnmarshalJSON

func (x *Type) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
example
codegen Module
codegen/api Module
examples
pb module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL