From 7b0577d9654c50750f7458b38baaef4caa2b08d2 Mon Sep 17 00:00:00 2001 From: dvladco Date: Tue, 16 Jul 2019 18:02:03 +0300 Subject: [PATCH] [fix] do not throw error if missing one of the field extensions --- Makefile | 1 + example/constructs.pb.go | 37 +++++++++++++++++++++++++++ example/options.pb.go | 54 ++++++++++++++++++++++++++++++++++++++++ pb/gql.pb.go | 34 ++++++++++++++----------- plugin/plugin.go | 4 --- 5 files changed, 112 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 0e16f54..fe94183 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: install example install: + go install github.com/gogo/protobuf/protoc-gen-gogo protoc --gogo_out=paths=source_relative,Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor:./pb \ -I=${GOPATH}/pkg/mod/ -I=./pb ./pb/*.proto go install ./protoc-gen-gql diff --git a/example/constructs.pb.go b/example/constructs.pb.go index b1736ff..408c560 100644 --- a/example/constructs.pb.go +++ b/example/constructs.pb.go @@ -11,6 +11,8 @@ import ( empty "github.com/golang/protobuf/ptypes/empty" timestamp "github.com/golang/protobuf/ptypes/timestamp" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -1865,6 +1867,41 @@ type ConstructsServer interface { CallWithId(context.Context, *Empty) (*Empty, error) } +// UnimplementedConstructsServer can be embedded to have forward compatible implementations. +type UnimplementedConstructsServer struct { +} + +func (*UnimplementedConstructsServer) Scalars_(ctx context.Context, req *Scalars) (*Scalars, error) { + return nil, status.Errorf(codes.Unimplemented, "method Scalars_ not implemented") +} +func (*UnimplementedConstructsServer) Repeated_(ctx context.Context, req *Repeated) (*Repeated, error) { + return nil, status.Errorf(codes.Unimplemented, "method Repeated_ not implemented") +} +func (*UnimplementedConstructsServer) Maps_(ctx context.Context, req *Maps) (*Maps, error) { + return nil, status.Errorf(codes.Unimplemented, "method Maps_ not implemented") +} +func (*UnimplementedConstructsServer) Any_(ctx context.Context, req *any.Any) (*Any, error) { + return nil, status.Errorf(codes.Unimplemented, "method Any_ not implemented") +} +func (*UnimplementedConstructsServer) Empty_(ctx context.Context, req *empty.Empty) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Empty_ not implemented") +} +func (*UnimplementedConstructsServer) Empty2_(ctx context.Context, req *EmptyRecursive) (*EmptyNested, error) { + return nil, status.Errorf(codes.Unimplemented, "method Empty2_ not implemented") +} +func (*UnimplementedConstructsServer) Empty3_(ctx context.Context, req *Empty3) (*Empty3, error) { + return nil, status.Errorf(codes.Unimplemented, "method Empty3_ not implemented") +} +func (*UnimplementedConstructsServer) Ref_(ctx context.Context, req *Ref) (*Ref, error) { + return nil, status.Errorf(codes.Unimplemented, "method Ref_ not implemented") +} +func (*UnimplementedConstructsServer) Oneof_(ctx context.Context, req *Oneof) (*Oneof, error) { + return nil, status.Errorf(codes.Unimplemented, "method Oneof_ not implemented") +} +func (*UnimplementedConstructsServer) CallWithId(ctx context.Context, req *Empty) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method CallWithId not implemented") +} + func RegisterConstructsServer(s *grpc.Server, srv ConstructsServer) { s.RegisterService(&_Constructs_serviceDesc, srv) } diff --git a/example/options.pb.go b/example/options.pb.go index 6c24fb6..ada514c 100644 --- a/example/options.pb.go +++ b/example/options.pb.go @@ -9,6 +9,8 @@ import ( _ "github.com/danielvladco/go-proto-gql/pb" proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -476,6 +478,41 @@ type ServiceServer interface { PubSub2(Service_PubSub2Server) error } +// UnimplementedServiceServer can be embedded to have forward compatible implementations. +type UnimplementedServiceServer struct { +} + +func (*UnimplementedServiceServer) Mutate1(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Mutate1 not implemented") +} +func (*UnimplementedServiceServer) Mutate2(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Mutate2 not implemented") +} +func (*UnimplementedServiceServer) Query1(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Query1 not implemented") +} +func (*UnimplementedServiceServer) Publish(srv Service_PublishServer) error { + return status.Errorf(codes.Unimplemented, "method Publish not implemented") +} +func (*UnimplementedServiceServer) Subscribe(req *Data, srv Service_SubscribeServer) error { + return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") +} +func (*UnimplementedServiceServer) PubSub1(srv Service_PubSub1Server) error { + return status.Errorf(codes.Unimplemented, "method PubSub1 not implemented") +} +func (*UnimplementedServiceServer) InvalidSubscribe1(srv Service_InvalidSubscribe1Server) error { + return status.Errorf(codes.Unimplemented, "method InvalidSubscribe1 not implemented") +} +func (*UnimplementedServiceServer) InvalidSubscribe2(req *Data, srv Service_InvalidSubscribe2Server) error { + return status.Errorf(codes.Unimplemented, "method InvalidSubscribe2 not implemented") +} +func (*UnimplementedServiceServer) InvalidSubscribe3(srv Service_InvalidSubscribe3Server) error { + return status.Errorf(codes.Unimplemented, "method InvalidSubscribe3 not implemented") +} +func (*UnimplementedServiceServer) PubSub2(srv Service_PubSub2Server) error { + return status.Errorf(codes.Unimplemented, "method PubSub2 not implemented") +} + func RegisterServiceServer(s *grpc.Server, srv ServiceServer) { s.RegisterService(&_Service_serviceDesc, srv) } @@ -851,6 +888,23 @@ type QueryServer interface { Subscribe(*Data, Query_SubscribeServer) error } +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Query1(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Query1 not implemented") +} +func (*UnimplementedQueryServer) Query2(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Query2 not implemented") +} +func (*UnimplementedQueryServer) Mutate1(ctx context.Context, req *Data) (*Data, error) { + return nil, status.Errorf(codes.Unimplemented, "method Mutate1 not implemented") +} +func (*UnimplementedQueryServer) Subscribe(req *Data, srv Query_SubscribeServer) error { + return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") +} + func RegisterQueryServer(s *grpc.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } diff --git a/pb/gql.pb.go b/pb/gql.pb.go index e0d1c03..fb98047 100644 --- a/pb/gql.pb.go +++ b/pb/gql.pb.go @@ -1,12 +1,14 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: gql.proto -package gql // import "github.com/danielvladco/go-proto-gql/pb" +package gql -import proto "github.com/gogo/protobuf/proto" -import fmt "fmt" -import math "math" -import descriptor "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + descriptor "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" + math "math" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -32,6 +34,7 @@ var Type_name = map[int32]string{ 1: "MUTATION", 2: "QUERY", } + var Type_value = map[string]int32{ "DEFAULT": 0, "MUTATION": 1, @@ -43,9 +46,11 @@ func (x Type) Enum() *Type { *p = x return p } + func (x Type) String() string { return proto.EnumName(Type_name, int32(x)) } + func (x *Type) UnmarshalJSON(data []byte) error { value, err := proto.UnmarshalJSONEnum(Type_value, data, "Type") if err != nil { @@ -54,8 +59,9 @@ func (x *Type) UnmarshalJSON(data []byte) error { *x = Type(value) return nil } + func (Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_gql_79dff684af960006, []int{0} + return fileDescriptor_f41526d4337e9701, []int{0} } type Field struct { @@ -71,7 +77,7 @@ func (m *Field) Reset() { *m = Field{} } func (m *Field) String() string { return proto.CompactTextString(m) } func (*Field) ProtoMessage() {} func (*Field) Descriptor() ([]byte, []int) { - return fileDescriptor_gql_79dff684af960006, []int{0} + return fileDescriptor_f41526d4337e9701, []int{0} } func (m *Field) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Field.Unmarshal(m, b) @@ -79,8 +85,8 @@ func (m *Field) XXX_Unmarshal(b []byte) error { func (m *Field) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return xxx_messageInfo_Field.Marshal(b, m, deterministic) } -func (dst *Field) XXX_Merge(src proto.Message) { - xxx_messageInfo_Field.Merge(dst, src) +func (m *Field) XXX_Merge(src proto.Message) { + xxx_messageInfo_Field.Merge(m, src) } func (m *Field) XXX_Size() int { return xxx_messageInfo_Field.Size(m) @@ -117,7 +123,7 @@ var E_RpcType = &proto.ExtensionDesc{ ExtensionType: (*Type)(nil), Field: 65030, Name: "gql.rpc_type", - Tag: "varint,65030,opt,name=rpc_type,json=rpcType,enum=gql.Type", + Tag: "varint,65030,opt,name=rpc_type,enum=gql.Type", Filename: "gql.proto", } @@ -126,7 +132,7 @@ var E_SvcType = &proto.ExtensionDesc{ ExtensionType: (*Type)(nil), Field: 65030, Name: "gql.svc_type", - Tag: "varint,65030,opt,name=svc_type,json=svcType,enum=gql.Type", + Tag: "varint,65030,opt,name=svc_type,enum=gql.Type", Filename: "gql.proto", } @@ -140,16 +146,16 @@ var E_Field = &proto.ExtensionDesc{ } func init() { - proto.RegisterType((*Field)(nil), "gql.Field") proto.RegisterEnum("gql.Type", Type_name, Type_value) + proto.RegisterType((*Field)(nil), "gql.Field") proto.RegisterExtension(E_RpcType) proto.RegisterExtension(E_SvcType) proto.RegisterExtension(E_Field) } -func init() { proto.RegisterFile("gql.proto", fileDescriptor_gql_79dff684af960006) } +func init() { proto.RegisterFile("gql.proto", fileDescriptor_f41526d4337e9701) } -var fileDescriptor_gql_79dff684af960006 = []byte{ +var fileDescriptor_f41526d4337e9701 = []byte{ // 312 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xcf, 0x4b, 0xc3, 0x30, 0x14, 0xc7, 0xed, 0x7e, 0xb8, 0xf6, 0x4d, 0x64, 0xe4, 0x20, 0x65, 0xa0, 0x0e, 0x4f, 0x43, 0x5d, diff --git a/plugin/plugin.go b/plugin/plugin.go index 718f6dd..cc6c46c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -415,8 +415,6 @@ func (p *Plugin) getMethodType(rpc *descriptor.MethodDescriptorProto) gql.Type { if tt != nil { return *tt } - } else { - p.Error(err) } } @@ -431,8 +429,6 @@ func (p *Plugin) getServiceType(svc *descriptor.ServiceDescriptorProto) gql.Type if tt != nil { return *tt } - } else { - p.Error(err) } }