From 32b34f7e894f3ca6bed979cea1f0a5422b312642 Mon Sep 17 00:00:00 2001 From: dvladco Date: Tue, 2 Apr 2019 13:22:10 +0300 Subject: [PATCH] feat: add gql resolver bindings to grpc service --- example/constructs.gqlgen.pb.go | 104 ++++++++++++----- example/constructs.gqlgen.pb.yml | 194 ++++++++++++++++++++----------- example/constructs.pb.graphqls | 8 +- example/options.gqlgen.pb.go | 63 +++++++++- example/options.gqlgen.pb.yml | 17 +-- example/options.pb.graphqls | 6 +- go.mod | 25 +--- go.sum | 76 ++++++------ gqltypes/types.go | 17 ++- protoc-gen-gogqlgen/main.go | 54 ++++++++- protoc-gen-gql/main.go | 2 +- protoc-gen-gqlgencfg/main.go | 9 +- 12 files changed, 390 insertions(+), 185 deletions(-) diff --git a/example/constructs.gqlgen.pb.go b/example/constructs.gqlgen.pb.go index 06e0f64..3043f88 100644 --- a/example/constructs.gqlgen.pb.go +++ b/example/constructs.gqlgen.pb.go @@ -1,25 +1,63 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: example/constructs.proto -package pb // import "github.com/danielvladco/go-proto-gql/example" - -import fmt "fmt" -import io "io" -import github_com_99designs_gqlgen_graphql "github.com/99designs/gqlgen/graphql" -import encoding_json "encoding/json" -import proto "github.com/golang/protobuf/proto" -import math "math" -import _ "github.com/golang/protobuf/ptypes/any" -import _ "github.com/golang/protobuf/ptypes/empty" -import _ "github.com/golang/protobuf/ptypes/timestamp" +package pb + +import ( + context "context" + encoding_json "encoding/json" + fmt "fmt" + github_com_99designs_gqlgen_graphql "github.com/99designs/gqlgen/graphql" + proto "github.com/golang/protobuf/proto" + _ "github.com/golang/protobuf/ptypes/any" + github_com_golang_protobuf_ptypes_any "github.com/golang/protobuf/ptypes/any" + _ "github.com/golang/protobuf/ptypes/empty" + github_com_golang_protobuf_ptypes_empty "github.com/golang/protobuf/ptypes/empty" + _ "github.com/golang/protobuf/ptypes/timestamp" + io "io" + math "math" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +type ConstructsGQLServer struct{ svc ConstructsServer } + +func (s *ConstructsGQLServer) ConstructsScalars(ctx context.Context, in *Scalars) (*Scalars, error) { + return s.svc.Scalars_(ctx, in) +} +func (s *ConstructsGQLServer) ConstructsRepeated(ctx context.Context, in *Repeated) (*Repeated, error) { + return s.svc.Repeated_(ctx, in) +} +func (s *ConstructsGQLServer) ConstructsMaps(ctx context.Context, in *Maps) (*Maps, error) { + return s.svc.Maps_(ctx, in) +} +func (s *ConstructsGQLServer) ConstructsAny(ctx context.Context, in *github_com_golang_protobuf_ptypes_any.Any) (*Any, error) { + return s.svc.Any_(ctx, in) +} +func (s *ConstructsGQLServer) ConstructsEmpty(ctx context.Context) (*bool, error) { + _, err := s.svc.Empty_(ctx, &github_com_golang_protobuf_ptypes_empty.Empty{}) + return nil, err +} +func (s *ConstructsGQLServer) ConstructsEmpty2(ctx context.Context) (*bool, error) { + _, err := s.svc.Empty2_(ctx, &EmptyRecursive{}) + return nil, err +} +func (s *ConstructsGQLServer) ConstructsEmpty3(ctx context.Context) (*bool, error) { + _, err := s.svc.Empty3_(ctx, &Empty3{}) + return nil, err +} +func (s *ConstructsGQLServer) ConstructsRef(ctx context.Context, in *Ref) (*Ref, error) { + return s.svc.Ref_(ctx, in) +} +func (s *ConstructsGQLServer) ConstructsOneof(ctx context.Context, in *Oneof) (*Oneof, error) { + return s.svc.Oneof_(ctx, in) +} + func MarshalMaps_Int32Int32Entry(mp map[int32]int32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -41,7 +79,7 @@ func UnmarshalMaps_Int32Int32Entry(v interface{}) (mp map[int32]int32, err error } func MarshalMaps_Int64Int64Entry(mp map[int64]int64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -63,7 +101,7 @@ func UnmarshalMaps_Int64Int64Entry(v interface{}) (mp map[int64]int64, err error } func MarshalMaps_Uint32Uint32Entry(mp map[uint32]uint32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -85,7 +123,7 @@ func UnmarshalMaps_Uint32Uint32Entry(v interface{}) (mp map[uint32]uint32, err e } func MarshalMaps_Uint64Uint64Entry(mp map[uint64]uint64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -107,7 +145,7 @@ func UnmarshalMaps_Uint64Uint64Entry(v interface{}) (mp map[uint64]uint64, err e } func MarshalMaps_Sint32Sint32Entry(mp map[int32]int32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -129,7 +167,7 @@ func UnmarshalMaps_Sint32Sint32Entry(v interface{}) (mp map[int32]int32, err err } func MarshalMaps_Sint64Sint64Entry(mp map[int64]int64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -151,7 +189,7 @@ func UnmarshalMaps_Sint64Sint64Entry(v interface{}) (mp map[int64]int64, err err } func MarshalMaps_Fixed32Fixed32Entry(mp map[uint32]uint32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -173,7 +211,7 @@ func UnmarshalMaps_Fixed32Fixed32Entry(v interface{}) (mp map[uint32]uint32, err } func MarshalMaps_Fixed64Fixed64Entry(mp map[uint64]uint64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -195,7 +233,7 @@ func UnmarshalMaps_Fixed64Fixed64Entry(v interface{}) (mp map[uint64]uint64, err } func MarshalMaps_Sfixed32Sfixed32Entry(mp map[int32]int32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -217,7 +255,7 @@ func UnmarshalMaps_Sfixed32Sfixed32Entry(v interface{}) (mp map[int32]int32, err } func MarshalMaps_Sfixed64Sfixed64Entry(mp map[int64]int64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -239,7 +277,7 @@ func UnmarshalMaps_Sfixed64Sfixed64Entry(v interface{}) (mp map[int64]int64, err } func MarshalMaps_BoolBoolEntry(mp map[bool]bool) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -261,7 +299,7 @@ func UnmarshalMaps_BoolBoolEntry(v interface{}) (mp map[bool]bool, err error) { } func MarshalMaps_StringStringEntry(mp map[string]string) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -283,7 +321,7 @@ func UnmarshalMaps_StringStringEntry(v interface{}) (mp map[string]string, err e } func MarshalMaps_StringBytesEntry(mp map[string][]byte) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -305,7 +343,7 @@ func UnmarshalMaps_StringBytesEntry(v interface{}) (mp map[string][]byte, err er } func MarshalMaps_StringFloatEntry(mp map[string]float32) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -327,7 +365,7 @@ func UnmarshalMaps_StringFloatEntry(v interface{}) (mp map[string]float32, err e } func MarshalMaps_StringDoubleEntry(mp map[string]float64) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -349,7 +387,7 @@ func UnmarshalMaps_StringDoubleEntry(v interface{}) (mp map[string]float64, err } func MarshalMaps_StringFooEntry(mp map[string]*Foo) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -371,7 +409,7 @@ func UnmarshalMaps_StringFooEntry(v interface{}) (mp map[string]*Foo, err error) } func MarshalMaps_StringBarEntry(mp map[string]Bar) github_com_99designs_gqlgen_graphql.Marshaler { - return graphql.WriterFunc(func(w io.Writer) { + return github_com_99designs_gqlgen_graphql.WriterFunc(func(w io.Writer) { err := encoding_json.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -392,6 +430,16 @@ func UnmarshalMaps_StringBarEntry(v interface{}) (mp map[string]Bar, err error) } } +type IsOneof_Oneof1 interface { + isOneof_Oneof1() +} +type IsOneof_Oneof2 interface { + isOneof_Oneof2() +} +type IsOneof_Oneof3 interface { + isOneof_Oneof3() +} + func (c *Bar) UnmarshalGQL(v interface{}) error { code, ok := v.(string) if ok { diff --git a/example/constructs.gqlgen.pb.yml b/example/constructs.gqlgen.pb.yml index 1027265..2e1cf9b 100644 --- a/example/constructs.gqlgen.pb.yml +++ b/example/constructs.gqlgen.pb.yml @@ -4,134 +4,196 @@ exec: filename: exec.go model: filename: models.go -resolver: - filename: resolvers.go models: Any: - model: github.com/danielvladco/go-proto-gql/gqltypes.Any + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Any Bar: - model: github.com/danielvladco/go-proto-gql/example.Bar + model: + - github.com/danielvladco/go-proto-gql/example.Bar Baz: - model: github.com/danielvladco/go-proto-gql/example.Baz + model: + - github.com/danielvladco/go-proto-gql/example.Baz BazInput: - model: github.com/danielvladco/go-proto-gql/example.Baz + model: + - github.com/danielvladco/go-proto-gql/example.Baz Bytes: - model: github.com/danielvladco/go-proto-gql/gqltypes.Bytes + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Bytes Float32: - model: github.com/danielvladco/go-proto-gql/gqltypes.Float32 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Float32 Foo: - model: github.com/danielvladco/go-proto-gql/example.Foo + model: + - github.com/danielvladco/go-proto-gql/example.Foo Foo_Foo2: - model: github.com/danielvladco/go-proto-gql/example.Foo_Foo2 + model: + - github.com/danielvladco/go-proto-gql/example.Foo_Foo2 Foo_Foo2Input: - model: github.com/danielvladco/go-proto-gql/example.Foo_Foo2 + model: + - github.com/danielvladco/go-proto-gql/example.Foo_Foo2 FooInput: - model: github.com/danielvladco/go-proto-gql/example.Foo + model: + - github.com/danielvladco/go-proto-gql/example.Foo Int32: - model: github.com/danielvladco/go-proto-gql/gqltypes.Int32 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Int32 Int64: - model: github.com/danielvladco/go-proto-gql/gqltypes.Int64 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Int64 IsOneof_Oneof1: - model: github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof1 + model: + - github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof1 IsOneof_Oneof2: - model: github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof2 + model: + - github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof2 IsOneof_Oneof3: - model: github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof3 + model: + - github.com/danielvladco/go-proto-gql/example.IsOneof_Oneof3 Maps: - model: github.com/danielvladco/go-proto-gql/example.Maps + model: + - github.com/danielvladco/go-proto-gql/example.Maps Maps_BoolBoolEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_BoolBoolEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_BoolBoolEntry Maps_Fixed32Fixed32Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Fixed32Fixed32Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Fixed32Fixed32Entry Maps_Fixed64Fixed64Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Fixed64Fixed64Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Fixed64Fixed64Entry Maps_Int32Int32Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Int32Int32Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Int32Int32Entry Maps_Int64Int64Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Int64Int64Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Int64Int64Entry Maps_Sfixed32Sfixed32Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Sfixed32Sfixed32Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Sfixed32Sfixed32Entry Maps_Sfixed64Sfixed64Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Sfixed64Sfixed64Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Sfixed64Sfixed64Entry Maps_Sint32Sint32Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Sint32Sint32Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Sint32Sint32Entry Maps_Sint64Sint64Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Sint64Sint64Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Sint64Sint64Entry Maps_StringBarEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringBarEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringBarEntry Maps_StringBytesEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringBytesEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringBytesEntry Maps_StringDoubleEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringDoubleEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringDoubleEntry Maps_StringFloatEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringFloatEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringFloatEntry Maps_StringFooEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringFooEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringFooEntry Maps_StringStringEntry: - model: github.com/danielvladco/go-proto-gql/example.Maps_StringStringEntry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_StringStringEntry Maps_Uint32Uint32Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Uint32Uint32Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Uint32Uint32Entry Maps_Uint64Uint64Entry: - model: github.com/danielvladco/go-proto-gql/example.Maps_Uint64Uint64Entry + model: + - github.com/danielvladco/go-proto-gql/example.Maps_Uint64Uint64Entry MapsInput: - model: github.com/danielvladco/go-proto-gql/example.Maps + model: + - github.com/danielvladco/go-proto-gql/example.Maps Oneof: - model: github.com/danielvladco/go-proto-gql/example.Oneof + model: + - github.com/danielvladco/go-proto-gql/example.Oneof Oneof_Param2: - model: github.com/danielvladco/go-proto-gql/example.Oneof_Param2 + model: + - github.com/danielvladco/go-proto-gql/example.Oneof_Param2 Oneof_Param3: - model: github.com/danielvladco/go-proto-gql/example.Oneof_Param3 + model: + - github.com/danielvladco/go-proto-gql/example.Oneof_Param3 Oneof_Param4: - model: github.com/danielvladco/go-proto-gql/example.Oneof_Param4 + model: + - github.com/danielvladco/go-proto-gql/example.Oneof_Param4 Oneof_Param5: - model: github.com/danielvladco/go-proto-gql/example.Oneof_Param5 + model: + - github.com/danielvladco/go-proto-gql/example.Oneof_Param5 Oneof_Param6: - model: github.com/danielvladco/go-proto-gql/example.Oneof_Param6 + model: + - github.com/danielvladco/go-proto-gql/example.Oneof_Param6 OneofInput: - model: github.com/danielvladco/go-proto-gql/example.Oneof + model: + - github.com/danielvladco/go-proto-gql/example.Oneof Ref: - model: github.com/danielvladco/go-proto-gql/example.Ref + model: + - github.com/danielvladco/go-proto-gql/example.Ref Ref_Bar: - model: github.com/danielvladco/go-proto-gql/example.Ref_Bar + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Bar Ref_BarInput: - model: github.com/danielvladco/go-proto-gql/example.Ref_Bar + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Bar Ref_Foo: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo Ref_Foo_Bar: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar Ref_Foo_Bar_En: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar_En + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar_En Ref_Foo_BarInput: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_Bar Ref_Foo_Baz_Gz: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_Baz_Gz + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_Baz_Gz Ref_Foo_Baz_GzInput: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_Baz_Gz + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_Baz_Gz Ref_Foo_En: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo_En + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo_En Ref_FooInput: - model: github.com/danielvladco/go-proto-gql/example.Ref_Foo + model: + - github.com/danielvladco/go-proto-gql/example.Ref_Foo RefInput: - model: github.com/danielvladco/go-proto-gql/example.Ref + model: + - github.com/danielvladco/go-proto-gql/example.Ref Repeated: - model: github.com/danielvladco/go-proto-gql/example.Repeated + model: + - github.com/danielvladco/go-proto-gql/example.Repeated RepeatedInput: - model: github.com/danielvladco/go-proto-gql/example.Repeated + model: + - github.com/danielvladco/go-proto-gql/example.Repeated Scalars: - model: github.com/danielvladco/go-proto-gql/example.Scalars + model: + - github.com/danielvladco/go-proto-gql/example.Scalars ScalarsInput: - model: github.com/danielvladco/go-proto-gql/example.Scalars + model: + - github.com/danielvladco/go-proto-gql/example.Scalars Uint32: - model: github.com/danielvladco/go-proto-gql/gqltypes.Uint32 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Uint32 Uint64: - model: github.com/danielvladco/go-proto-gql/gqltypes.Uint64 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Uint64 google_protobuf_Timestamp: - model: github.com/golang/protobuf/ptypes/timestamp.Timestamp + model: + - github.com/golang/protobuf/ptypes/timestamp.Timestamp google_protobuf_TimestampInput: - model: github.com/golang/protobuf/ptypes/timestamp.Timestamp + model: + - github.com/golang/protobuf/ptypes/timestamp.Timestamp pb_Any: - model: github.com/danielvladco/go-proto-gql/example.Any + model: + - github.com/danielvladco/go-proto-gql/example.Any pb_Timestamp: - model: github.com/danielvladco/go-proto-gql/example.Timestamp + model: + - github.com/danielvladco/go-proto-gql/example.Timestamp pb_TimestampInput: - model: github.com/danielvladco/go-proto-gql/example.Timestamp + model: + - github.com/danielvladco/go-proto-gql/example.Timestamp diff --git a/example/constructs.pb.graphqls b/example/constructs.pb.graphqls index c602ac2..01bd510 100644 --- a/example/constructs.pb.graphqls +++ b/example/constructs.pb.graphqls @@ -338,7 +338,7 @@ type pb_Timestamp { time: String } -union IsOneof_Oneof1 = Oneof_Param3 | Oneof_Param2 +union IsOneof_Oneof1 = Oneof_Param2 | Oneof_Param3 union IsOneof_Oneof2 = Oneof_Param4 | Oneof_Param5 @@ -365,9 +365,9 @@ type Mutation { constructsRepeated_(in: RepeatedInput): Repeated constructsMaps_(in: MapsInput): Maps constructsAny_(in: Any): pb_Any - constructsEmpty_: Boolean! - constructsEmpty2_: Boolean! - constructsEmpty3_: Boolean! + constructsEmpty_: Boolean + constructsEmpty2_: Boolean + constructsEmpty3_: Boolean constructsRef_(in: RefInput): Ref constructsOneof_(in: OneofInput): Oneof } diff --git a/example/options.gqlgen.pb.go b/example/options.gqlgen.pb.go index 56cbec5..77783dc 100644 --- a/example/options.gqlgen.pb.go +++ b/example/options.gqlgen.pb.go @@ -1,15 +1,66 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: example/options.proto -package pb // import "github.com/danielvladco/go-proto-gql/example" +package pb -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import _ "github.com/danielvladco/go-proto-gql" -import _ "github.com/mwitkow/go-proto-validators" +import ( + context "context" + fmt "fmt" + _ "github.com/danielvladco/go-proto-gql" + proto "github.com/golang/protobuf/proto" + _ "github.com/mwitkow/go-proto-validators" + math "math" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf + +type ServiceGQLServer struct{ svc ServiceServer } + +func (s *ServiceGQLServer) ServiceMutate1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Mutate1(ctx, in) +} +func (s *ServiceGQLServer) ServiceMutate2(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Mutate2(ctx, in) +} +func (s *ServiceGQLServer) ServiceQuery1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Query1(ctx, in) +} +func (s *ServiceGQLServer) ServicePublish(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Publish(ctx, in) +} +func (s *ServiceGQLServer) ServiceSubscribe(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Subscribe(ctx, in) +} +func (s *ServiceGQLServer) ServicePubSub1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.PubSub1(ctx, in) +} +func (s *ServiceGQLServer) ServiceInvalidSubscribe1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.InvalidSubscribe1(ctx, in) +} +func (s *ServiceGQLServer) ServiceInvalidSubscribe2(ctx context.Context, in *Data) (*Data, error) { + return s.svc.InvalidSubscribe2(ctx, in) +} +func (s *ServiceGQLServer) ServiceInvalidSubscribe3(ctx context.Context, in *Data) (*Data, error) { + return s.svc.InvalidSubscribe3(ctx, in) +} +func (s *ServiceGQLServer) ServicePubSub2(ctx context.Context, in *Data) (*Data, error) { + return s.svc.PubSub2(ctx, in) +} + +type QueryGQLServer struct{ svc QueryServer } + +func (s *QueryGQLServer) QueryQuery1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Query1(ctx, in) +} +func (s *QueryGQLServer) QueryQuery2(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Query2(ctx, in) +} +func (s *QueryGQLServer) QueryMutate1(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Mutate1(ctx, in) +} +func (s *QueryGQLServer) QuerySubscribe(ctx context.Context, in *Data) (*Data, error) { + return s.svc.Subscribe(ctx, in) +} diff --git a/example/options.gqlgen.pb.yml b/example/options.gqlgen.pb.yml index 044abdb..4d7265f 100644 --- a/example/options.gqlgen.pb.yml +++ b/example/options.gqlgen.pb.yml @@ -4,16 +4,19 @@ exec: filename: exec.go model: filename: models.go -resolver: - filename: resolvers.go models: Data: - model: github.com/danielvladco/go-proto-gql/example.Data + model: + - github.com/danielvladco/go-proto-gql/example.Data DataInput: - model: github.com/danielvladco/go-proto-gql/example.Data + model: + - github.com/danielvladco/go-proto-gql/example.Data Float32: - model: github.com/danielvladco/go-proto-gql/gqltypes.Float32 + model: + - github.com/danielvladco/go-proto-gql/gqltypes.Float32 Foo2: - model: github.com/danielvladco/go-proto-gql/example.Foo2 + model: + - github.com/danielvladco/go-proto-gql/example.Foo2 Foo2Input: - model: github.com/danielvladco/go-proto-gql/example.Foo2 + model: + - github.com/danielvladco/go-proto-gql/example.Foo2 diff --git a/example/options.pb.graphqls b/example/options.pb.graphqls index ecc833c..1068c82 100644 --- a/example/options.pb.graphqls +++ b/example/options.pb.graphqls @@ -34,11 +34,11 @@ type Mutation { serviceMutate2(in: DataInput): Data servicePublish(in: DataInput): Data # See the Subscription with the same name - servicePubSub1(in: DataInput): Boolean! + servicePubSub1(in: DataInput): Boolean # See the Subscription with the same name - serviceInvalidSubscribe3(in: DataInput): Boolean! + serviceInvalidSubscribe3(in: DataInput): Boolean # See the Subscription with the same name - servicePubSub2(in: DataInput): Boolean! + servicePubSub2(in: DataInput): Boolean queryMutate1(in: DataInput): Data } diff --git a/go.mod b/go.mod index 9d88116..c176228 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,12 @@ module github.com/danielvladco/go-proto-gql require ( - github.com/99designs/gqlgen v0.7.1 - github.com/agnivade/levenshtein v1.0.1 // indirect - github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gogo/protobuf v1.2.0 - github.com/golang/protobuf v1.2.0 - github.com/kr/pretty v0.1.0 // indirect - github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007 + github.com/99designs/gqlgen v0.8.2 + github.com/gogo/protobuf v1.2.1 + github.com/golang/protobuf v1.3.1 + github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 github.com/pkg/errors v0.8.1 - github.com/sergi/go-diff v1.0.0 // indirect - github.com/stretchr/testify v1.3.0 // indirect - github.com/vektah/gqlparser v1.0.0 // indirect - golang.org/x/net v0.0.0-20190119204137-ed066c81e75e - golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect - golang.org/x/sys v0.0.0-20190124100055-b90733256f2e // indirect - golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 // indirect - golang.org/x/tools v0.0.0-20190124004107-78ee07aa9465 // indirect - google.golang.org/genproto v0.0.0-20190123001331-8819c946db44 // indirect - google.golang.org/grpc v1.18.0 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect + golang.org/x/net v0.0.0-20190328230028-74de082e2cca + google.golang.org/grpc v1.19.1 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 842c74e..fe3e2eb 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/99designs/gqlgen v0.7.1 h1:uRf7C+/33spvj24B5fKAExQcHbZkJHE5yjoSgSYBmiE= -github.com/99designs/gqlgen v0.7.1/go.mod h1:KSQDfLlTTGmzlRgLGm6HeKKKo598l5E2svEM6Nz2Jnw= +github.com/99designs/gqlgen v0.8.2 h1:xOkDPWn/MZjkQ32pu6Axx15mNah0NAq9WalFqT+RavA= +github.com/99designs/gqlgen v0.8.2/go.mod h1:aLyJw9xUgdJxZ8EqNQxo2pGFhXXJ/hq8t7J4yn8TgI4= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= @@ -9,69 +10,76 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= +github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007 h1:28i1IjGcx8AofiB4N3q5Yls55VEaitzuEPkFJEVgGkA= -github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007/go.mod h1:m2XC9Qq0AlmmVksL6FktJCdTYyLk7V3fKyp0sl1yWQo= +github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 h1:RY9I2vt95pyT12MKfJo1Ck3O+NPQqlukBahURwDtJBc= +github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944/go.mod h1:m2XC9Qq0AlmmVksL6FktJCdTYyLk7V3fKyp0sl1yWQo= +github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/vektah/gqlparser v1.0.0 h1:sa/YH/EczjNUFh/ww8ZOsEt/Z7bUMVHI/PH8U0a+taM= -github.com/vektah/gqlparser v1.0.0/go.mod h1:K4QdSSpS2XiHHwzb18kWh3iBljB8rLC8okGXsnQy3Nc= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/vektah/dataloaden v0.2.0/go.mod h1:vxM6NuRlgiR0M6wbVTJeKp9vQIs81ZMfCYO+4yq/jbE= +github.com/vektah/gqlparser v1.1.2 h1:ZsyLGn7/7jDNI+y4SEhI4yAxRChlv15pUHMjijT+e68= +github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= +golang.org/x/net v0.0.0-20180404174746-b3c676e531a6/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190119204137-ed066c81e75e h1:MDa3fSUp6MdYHouVmCCNz/zaH2a6CRcxY3VhT/K3C5Q= -golang.org/x/net v0.0.0-20190119204137-ed066c81e75e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190328230028-74de082e2cca h1:hyA6yiAgbUwuWqtscNvWAI7U1CtlaD1KilQ6iudt1aI= +golang.org/x/net v0.0.0-20190328230028-74de082e2cca/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e h1:3GIlrlVLfkoipSReOMNAgApI0ajnalyLa/EZHHca/XI= -golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190124004107-78ee07aa9465 h1:z1zWb2F6a0UkU9Kyl0B4+xIt/1oatpNlk9B9wWku/mY= -golang.org/x/tools v0.0.0-20190124004107-78ee07aa9465/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6 h1:iZgcI2DDp6zW5v9Z/5+f0NuqoxNdmzg4hivjk2WLXpY= +golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190123001331-8819c946db44 h1:9u28q5XSBq/QWKRyrhsE2pOAKf+5fR68Vj5prhzqUYY= -google.golang.org/genproto v0.0.0-20190123001331-8819c946db44/go.mod h1:L3J43x8/uS+qIUoksaLKe6OS3nUKxOKuIFz1sl2/jx4= -google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.18.0 h1:IZl7mfBGfbhYx2p2rKRtYgDFw6SBz+kclmxYrCksPPA= -google.golang.org/grpc v1.18.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +google.golang.org/grpc v1.19.1 h1:TrBcJ1yqAl1G++wO39nD/qtgpsW9/1+QGrluyMGEYgM= +google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= +sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k= diff --git a/gqltypes/types.go b/gqltypes/types.go index 7bc311e..94551cc 100644 --- a/gqltypes/types.go +++ b/gqltypes/types.go @@ -1,6 +1,7 @@ package gqltypes import ( + "context" "encoding/json" "fmt" "io" @@ -10,6 +11,10 @@ import ( "github.com/golang/protobuf/ptypes/any" ) +type DummyResolver struct{} + +func (r *DummyResolver) Dummy(ctx context.Context) (*bool, error) { return nil, nil } + func MarshalBytes(b []byte) graphql.Marshaler { return graphql.WriterFunc(func(w io.Writer) { _, _ = fmt.Fprintf(w, "%q", string(b)) @@ -29,10 +34,10 @@ func UnmarshalBytes(v interface{}) ([]byte, error) { } } -func MarshalAny(any *any.Any) graphql.Marshaler { +func MarshalAny(any any.Any) graphql.Marshaler { return graphql.WriterFunc(func(w io.Writer) { d := &ptypes.DynamicAny{} - if err := ptypes.UnmarshalAny(any, d); err != nil { + if err := ptypes.UnmarshalAny(&any, d); err != nil { panic("unable to unmarshal any: " + err.Error()) return } @@ -43,14 +48,14 @@ func MarshalAny(any *any.Any) graphql.Marshaler { }) } -func UnmarshalAny(v interface{}) (*any.Any, error) { +func UnmarshalAny(v interface{}) (any.Any, error) { switch v := v.(type) { case []byte: - return nil, nil //TODO add an unmarshal mechanism + return any.Any{}, nil //TODO add an unmarshal mechanism case json.RawMessage: - return nil, nil + return any.Any{}, nil default: - return nil, fmt.Errorf("%T is not json.RawMessage", v) + return any.Any{}, fmt.Errorf("%T is not json.RawMessage", v) } } diff --git a/protoc-gen-gogqlgen/main.go b/protoc-gen-gogqlgen/main.go index 81bc473..f0b11cb 100644 --- a/protoc-gen-gogqlgen/main.go +++ b/protoc-gen-gogqlgen/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + gqlplugin "github.com/danielvladco/go-proto-gql/plugin" "io/ioutil" "os" "strconv" @@ -46,7 +47,12 @@ func main() { gen.WrapTypes() gen.SetPackageNames() gen.BuildTypeNameMap() - gen.GeneratePlugin(&plugin{useGogoImport: useGogoImport, enums: make(map[string]struct{}), messages: make(map[string]struct{})}) + gen.GeneratePlugin(&plugin{ + useGogoImport: useGogoImport, + enums: make(map[string]struct{}), + messages: make(map[string]struct{}), + Plugin: gqlplugin.NewPlugin(), + }) for i := 0; i < len(gen.Response.File); i++ { gen.Response.File[i].Name = proto.String(strings.Replace(*gen.Response.File[i].Name, ".pb.go", ".gqlgen.pb.go", -1)) @@ -64,12 +70,13 @@ func main() { } type plugin struct { - *generator.Generator + *gqlplugin.Plugin generator.PluginImports ioPkg generator.Single fmtPkg generator.Single graphqlPkg generator.Single jsonPkg generator.Single + contextPkg generator.Single enums map[string]struct{} messages map[string]struct{} @@ -77,7 +84,7 @@ type plugin struct { useGogoImport bool } -func (p *plugin) Name() string { return "gqlenum" } +func (p *plugin) Name() string { return "gogqlgen" } func (p *plugin) Init(g *generator.Generator) { p.Generator = g } func (p *plugin) Generate(file *generator.FileDescriptor) { if !p.useGogoImport { @@ -89,9 +96,38 @@ func (p *plugin) Generate(file *generator.FileDescriptor) { p.ioPkg = p.NewImport("io") p.graphqlPkg = p.NewImport("github.com/99designs/gqlgen/graphql") p.jsonPkg = p.NewImport("encoding/json") + p.contextPkg = p.NewImport("context") + p.Scalars() for _, r := range p.Request.FileToGenerate { if r == file.GetName() { + p.InitFile(file) + for _, svc := range file.GetService() { + p.Generator.P(`type `, svc.GetName(), `GQLServer struct { svc `, svc.GetName(), `Server }`) + for _, rpc := range svc.GetMethod() { + methodName := strings.Replace(generator.CamelCase(svc.GetName()+rpc.GetName()), "_", "", -1) + typeInObj := p.TypeNameByObject(rpc.GetInputType()) + p.NewImport(string(typeInObj.GoImportPath())) + typeOutObj := p.TypeNameByObject(rpc.GetOutputType()) + typeIn := generator.CamelCaseSlice(typeInObj.TypeName()) + typeOut := generator.CamelCaseSlice(typeOutObj.TypeName()) + if p.DefaultPackageName(typeInObj) != "" { + typeIn = p.NewImport(string(typeInObj.GoImportPath())).Use() + "." + typeIn + } + if p.DefaultPackageName(typeOutObj) != "" { + typeOut = p.NewImport(string(typeOutObj.GoImportPath())).Use() + "." + typeOut + } + in, inref := ", in *"+typeIn, ", in" + if p.IsEmpty(p.Inputs()[rpc.GetInputType()]) { + in, inref = "", ", &"+typeIn+"{}" + } + if p.IsEmpty(p.Types()[rpc.GetOutputType()]) { + p.Generator.P("func (s *", svc.GetName(), "GQLServer) ", methodName, "(ctx ", p.contextPkg.Use(), ".Context", in, ") (*bool, error) { _, err := s.svc.", generator.CamelCase(rpc.GetName()), "(ctx", inref, ")\n return nil, err }") + } else { + p.Generator.P("func (s *", svc.GetName(), "GQLServer) ", methodName, "(ctx ", p.contextPkg.Use(), ".Context", in, ") (*", typeOut, ", error) { return s.svc.", generator.CamelCase(rpc.GetName()), "(ctx", inref, ") }") + } + } + } for _, msg := range file.Messages() { if msg.GetOptions().GetMapEntry() { key, value := msg.GetMapFields() @@ -101,9 +137,9 @@ func (p *plugin) Generate(file *generator.FileDescriptor) { valType, _ := p.GoType(msg, value) mapType := fmt.Sprintf("map[%s]%s", keyType, valType) - p.P(` + p.Generator.P(` func Marshal`, mapName, `(mp `, mapType, `) `, p.graphqlPkg.Use(), `.Marshaler { - return graphql.WriterFunc(func(w `, p.ioPkg.Use(), `.Writer) { + return `, p.graphqlPkg.Use(), `.WriterFunc(func(w `, p.ioPkg.Use(), `.Writer) { err := `, p.jsonPkg.Use(), `.NewEncoder(w).Encode(mp) if err != nil { panic("stupid map") @@ -125,10 +161,15 @@ func Unmarshal`, mapName, `(v interface{}) (mp `, mapType, `, err error) { } `) } + for _, oneof := range msg.OneofDecl { + oneofName := append(msg.TypeName(), oneof.GetName()) + p.Generator.P(`type Is`, generator.CamelCaseSlice(oneofName), + " interface{\n\tis", generator.CamelCaseSlice(oneofName), "()\n}") + } } for _, enum := range file.Enums() { enumType := generator.CamelCaseSlice(enum.TypeName()) - p.P(` + p.Generator.P(` func (c *`, enumType, `) UnmarshalGQL(v interface{}) error { code, ok := v.(string) if ok { @@ -143,6 +184,7 @@ func (c `, enumType, `) MarshalGQL(w `, p.ioPkg.Use(), `.Writer) { } `) } + } } } diff --git a/protoc-gen-gql/main.go b/protoc-gen-gql/main.go index 9799c13..774f689 100644 --- a/protoc-gen-gql/main.go +++ b/protoc-gen-gql/main.go @@ -216,7 +216,7 @@ func (p *plugin) generate(file *generator.FileDescriptor) { func (p *plugin) renderMethod(methods []*Method) { for _, m := range methods { - in, out := "", "Boolean!" + in, out := "", "Boolean" // some scalars can be used as inputs such as 'Any' if scalar, ok := p.Scalars()[m.InputType]; ok { diff --git a/protoc-gen-gqlgencfg/main.go b/protoc-gen-gqlgencfg/main.go index 6b11289..230e713 100644 --- a/protoc-gen-gqlgencfg/main.go +++ b/protoc-gen-gqlgencfg/main.go @@ -7,7 +7,7 @@ import ( "path" "strings" - "github.com/99designs/gqlgen/codegen" + codegen "github.com/99designs/gqlgen/codegen/config" . "github.com/danielvladco/go-proto-gql/plugin" "github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/protoc-gen-gogo/generator" @@ -37,7 +37,7 @@ func main() { for i := 0; i < fileLen; i++ { gen.Response.File[i].Name = proto.String(strings.Replace(gen.Response.File[i].GetName(), ".pb.go", ".gqlgen.pb.yml", -1)) _, file := path.Split(strings.Replace(gen.Response.File[i].GetName(), ".gqlgen.pb.yml", ".pb.graphqls", -1)) - p.config[i].SchemaFilename = []string{file} + p.config[i].SchemaFilename = []string{path.Join(".", file)} b, err := yaml.Marshal(p.config[i]) if err != nil { p.Error(errors.New("cannot create codegen.yml")) @@ -72,7 +72,6 @@ func (p *plugin) Generate(file *generator.FileDescriptor) { cfg := &codegen.Config{ SchemaFilename: []string{}, Exec: codegen.PackageConfig{Filename: "exec.go"}, - Resolver: codegen.PackageConfig{Filename: "resolvers.go"}, Model: codegen.PackageConfig{Filename: "models.go"}, Models: make(codegen.TypeMap), } @@ -83,10 +82,10 @@ func (p *plugin) Generate(file *generator.FileDescriptor) { } if m, ok := cfg.Models[key]; ok { - m.Model = typ.PackageDir + "." + typ.TypeName + m.Model = []string{typ.PackageDir + "." + typ.TypeName} cfg.Models[key] = m } else { - cfg.Models[key] = codegen.TypeMapEntry{Model: typ.PackageDir + "." + typ.TypeName} + cfg.Models[key] = codegen.TypeMapEntry{Model: []string{typ.PackageDir + "." + typ.TypeName}} } } p.config = append(p.config, cfg)