diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index cc1c3fe..ce27b7c 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -68,6 +68,9 @@ jobs: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 + - name: Tests + run: make test + - name: Build example/starwars run: make build_all working-directory: example/starwars diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed0029..7733efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## UNRELEASED - Resolve camelCase enum values ([#13](https://github.com/alehechka/grpc-graphql-gateway/pull/13)) +- Remove field_camel and add field_proto CLI arg ([#14](https://github.com/alehechka/grpc-graphql-gateway/pull/14)) ## [v0.2.4](https://github.com/alehechka/grpc-graphql-gateway/releases/tag/v0.2.4) diff --git a/Makefile b/Makefile index 540dd74..e700a85 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ lint: golangci-lint run test: + cd runtime/tests ; make build go list ./... | xargs go test build: test plugin @@ -41,3 +42,7 @@ compile: compile_mac: cd ${GRAPHQL_CMD} && GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ${GOPATH}/bin/${GRAPHQL_CMD} + +build_examples: + cd example/starwars ; make build_all + cd example/greeter ; make build_all \ No newline at end of file diff --git a/example/greeter/greeter/greeter.graphql.go b/example/greeter/greeter/greeter.graphql.go index 4ee5c30..173a607 100644 --- a/example/greeter/greeter/greeter.graphql.go +++ b/example/greeter/greeter/greeter.graphql.go @@ -195,7 +195,7 @@ func (x *graphql__resolver_Greeter) GetQueries(conn *grpc.ClientConn) graphql.Fi }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req HelloRequest - if err := runtime.MarshalRequest(p.Args, &req, false); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for hello") } client := NewGreeterClient(conn) @@ -203,7 +203,7 @@ func (x *graphql__resolver_Greeter) GetQueries(conn *grpc.ClientConn) graphql.Fi if err != nil { return nil, errors.Wrap(err, "Failed to call RPC SayHello") } - return resp, nil + return runtime.MarshalResponse(resp), nil }, }, "goodbye": &graphql.Field{ @@ -217,7 +217,7 @@ func (x *graphql__resolver_Greeter) GetQueries(conn *grpc.ClientConn) graphql.Fi }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req GoodbyeRequest - if err := runtime.MarshalRequest(p.Args, &req, false); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for goodbye") } client := NewGreeterClient(conn) @@ -225,7 +225,7 @@ func (x *graphql__resolver_Greeter) GetQueries(conn *grpc.ClientConn) graphql.Fi if err != nil { return nil, errors.Wrap(err, "Failed to call RPC SayGoodbye") } - return resp, nil + return runtime.MarshalResponse(resp), nil }, }, } diff --git a/example/starwars/Makefile b/example/starwars/Makefile index 24c59fa..4068d6e 100644 --- a/example/starwars/Makefile +++ b/example/starwars/Makefile @@ -14,7 +14,6 @@ build: init --plugin=../../dist/protoc-gen-graphql \ --graphql_out=${SPECDIR} \ --graphql_opt=paths=source_relative \ - --graphql_opt=field_camel \ --go_out=:${SPECDIR} \ --go_opt=paths=source_relative \ --go-grpc_out=:${SPECDIR} \ diff --git a/example/starwars/app/grpc/main.go b/example/starwars/app/grpc/main.go index f9c4826..419252d 100644 --- a/example/starwars/app/grpc/main.go +++ b/example/starwars/app/grpc/main.go @@ -262,7 +262,6 @@ func (s *Server) ListHumans( } cs = append(cs, c) } - log.Println(cs) return &starwars.ListHumansResponse{ Humans: cs, }, nil diff --git a/example/starwars/proto/starwars/starwars.proto b/example/starwars/proto/starwars/starwars.proto index f8fee61..5c466d6 100644 --- a/example/starwars/proto/starwars/starwars.proto +++ b/example/starwars/proto/starwars/starwars.proto @@ -10,8 +10,8 @@ message Character { int64 id = 1; string name = 2; repeated Character friends = 3; - repeated Episode appears_in = 4; - string home_planet = 5; + repeated Episode appears_in = 4 [json_name = "appearances"]; + string home_planet = 5 [json_name = "home"]; string primary_function = 6; Type type = 7; } @@ -35,12 +35,12 @@ message GetHeroRequest { message GetHumanRequest { // id of the human - int64 id = 1 [(graphql.field) = {required: true}]; + int64 id = 1 [json_name = "humanID", (graphql.field) = {required: true}]; } message GetDroidRequest { // id of the droid - int64 id = 1 [(graphql.field) = {required: true}]; + int64 id = 1 [json_name = "droidID", (graphql.field) = {required: true}]; } message ListEmptyRequest { diff --git a/example/starwars/spec/starwars/starwars.graphql.go b/example/starwars/spec/starwars/starwars.graphql.go index 673194c..2cb0534 100644 --- a/example/starwars/spec/starwars/starwars.graphql.go +++ b/example/starwars/spec/starwars/starwars.graphql.go @@ -86,10 +86,10 @@ func Gql__interface_Character() *graphql.Interface { "name": &graphql.Field{ Type: graphql.String, }, - "appearsIn": &graphql.Field{ + "appearances": &graphql.Field{ Type: graphql.NewList(Gql__enum_Episode()), }, - "homePlanet": &graphql.Field{ + "home": &graphql.Field{ Type: graphql.String, }, "primaryFunction": &graphql.Field{ @@ -154,7 +154,7 @@ func Gql__type_GetHumanRequest() *graphql.Object { gql__type_GetHumanRequest = graphql.NewObject(graphql.ObjectConfig{ Name: "Starwars_Type_GetHumanRequest", Fields: graphql.Fields{ - "id": &graphql.Field{ + "humanID": &graphql.Field{ Type: graphql.NewNonNull(graphql.Int), Description: `id of the human`, }, @@ -184,7 +184,7 @@ func Gql__type_GetDroidRequest() *graphql.Object { gql__type_GetDroidRequest = graphql.NewObject(graphql.ObjectConfig{ Name: "Starwars_Type_GetDroidRequest", Fields: graphql.Fields{ - "id": &graphql.Field{ + "droidID": &graphql.Field{ Type: graphql.NewNonNull(graphql.Int), Description: `id of the droid`, }, @@ -208,10 +208,10 @@ func Gql__type_Character() *graphql.Object { "friends": &graphql.Field{ Type: graphql.NewList(Gql__interface_Character()), }, - "appearsIn": &graphql.Field{ + "appearances": &graphql.Field{ Type: graphql.NewList(Gql__enum_Episode()), }, - "homePlanet": &graphql.Field{ + "home": &graphql.Field{ Type: graphql.String, }, "primaryFunction": &graphql.Field{ @@ -276,7 +276,7 @@ func Gql__input_GetHumanRequest() *graphql.InputObject { gql__input_GetHumanRequest = graphql.NewInputObject(graphql.InputObjectConfig{ Name: "Starwars_Input_GetHumanRequest", Fields: graphql.InputObjectConfigFieldMap{ - "id": &graphql.InputObjectFieldConfig{ + "humanID": &graphql.InputObjectFieldConfig{ Description: `id of the human`, Type: graphql.NewNonNull(graphql.Int), }, @@ -306,7 +306,7 @@ func Gql__input_GetDroidRequest() *graphql.InputObject { gql__input_GetDroidRequest = graphql.NewInputObject(graphql.InputObjectConfig{ Name: "Starwars_Input_GetDroidRequest", Fields: graphql.InputObjectConfigFieldMap{ - "id": &graphql.InputObjectFieldConfig{ + "droidID": &graphql.InputObjectFieldConfig{ Description: `id of the droid`, Type: graphql.NewNonNull(graphql.Int), }, @@ -330,10 +330,10 @@ func Gql__input_Character() *graphql.InputObject { "friends": &graphql.InputObjectFieldConfig{ Type: graphql.NewList(Gql__interface_Character()), }, - "appearsIn": &graphql.InputObjectFieldConfig{ + "appearances": &graphql.InputObjectFieldConfig{ Type: graphql.NewList(Gql__enum_Episode()), }, - "homePlanet": &graphql.InputObjectFieldConfig{ + "home": &graphql.InputObjectFieldConfig{ Type: graphql.String, }, "primaryFunction": &graphql.InputObjectFieldConfig{ @@ -400,7 +400,7 @@ func (x *graphql__resolver_StartwarsService) GetQueries(conn *grpc.ClientConn) g }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req GetHeroRequest - if err := runtime.MarshalRequest(p.Args, &req, true); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for hero") } client := NewStartwarsServiceClient(conn) @@ -414,14 +414,14 @@ func (x *graphql__resolver_StartwarsService) GetQueries(conn *grpc.ClientConn) g "human": &graphql.Field{ Type: Gql__type_Character(), Args: graphql.FieldConfigArgument{ - "id": &graphql.ArgumentConfig{ + "humanID": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Int), Description: `id of the human`, }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req GetHumanRequest - if err := runtime.MarshalRequest(p.Args, &req, true); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for human") } client := NewStartwarsServiceClient(conn) @@ -435,14 +435,14 @@ func (x *graphql__resolver_StartwarsService) GetQueries(conn *grpc.ClientConn) g "droid": &graphql.Field{ Type: Gql__type_Character(), Args: graphql.FieldConfigArgument{ - "id": &graphql.ArgumentConfig{ + "droidID": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Int), Description: `id of the droid`, }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req GetDroidRequest - if err := runtime.MarshalRequest(p.Args, &req, true); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for droid") } client := NewStartwarsServiceClient(conn) @@ -458,7 +458,7 @@ func (x *graphql__resolver_StartwarsService) GetQueries(conn *grpc.ClientConn) g Args: graphql.FieldConfigArgument{}, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req ListEmptyRequest - if err := runtime.MarshalRequest(p.Args, &req, true); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for humans") } client := NewStartwarsServiceClient(conn) @@ -474,7 +474,7 @@ func (x *graphql__resolver_StartwarsService) GetQueries(conn *grpc.ClientConn) g Args: graphql.FieldConfigArgument{}, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req ListEmptyRequest - if err := runtime.MarshalRequest(p.Args, &req, true); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for droids") } client := NewStartwarsServiceClient(conn) diff --git a/example/starwars/spec/starwars/starwars.pb.go b/example/starwars/spec/starwars/starwars.pb.go index e68ebff..2109310 100644 --- a/example/starwars/spec/starwars/starwars.pb.go +++ b/example/starwars/spec/starwars/starwars.pb.go @@ -127,8 +127,8 @@ type Character struct { Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Friends []*Character `protobuf:"bytes,3,rep,name=friends,proto3" json:"friends,omitempty"` - AppearsIn []Episode `protobuf:"varint,4,rep,packed,name=appears_in,json=appearsIn,proto3,enum=startwars.Episode" json:"appears_in,omitempty"` - HomePlanet string `protobuf:"bytes,5,opt,name=home_planet,json=homePlanet,proto3" json:"home_planet,omitempty"` + AppearsIn []Episode `protobuf:"varint,4,rep,packed,name=appears_in,json=appearances,proto3,enum=startwars.Episode" json:"appears_in,omitempty"` + HomePlanet string `protobuf:"bytes,5,opt,name=home_planet,json=home,proto3" json:"home_planet,omitempty"` PrimaryFunction string `protobuf:"bytes,6,opt,name=primary_function,json=primaryFunction,proto3" json:"primary_function,omitempty"` Type Type `protobuf:"varint,7,opt,name=type,proto3,enum=startwars.Type" json:"type,omitempty"` } @@ -268,7 +268,7 @@ type GetHumanRequest struct { unknownFields protoimpl.UnknownFields // id of the human - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id int64 `protobuf:"varint,1,opt,name=id,json=humanID,proto3" json:"id,omitempty"` } func (x *GetHumanRequest) Reset() { @@ -316,7 +316,7 @@ type GetDroidRequest struct { unknownFields protoimpl.UnknownFields // id of the droid - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Id int64 `protobuf:"varint,1,opt,name=id,json=droidID,proto3" json:"id,omitempty"` } func (x *GetDroidRequest) Reset() { @@ -496,80 +496,80 @@ var file_starwars_starwars_proto_rawDesc = []byte{ 0x0a, 0x17, 0x73, 0x74, 0x61, 0x72, 0x77, 0x61, 0x72, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x1a, 0x15, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2f, 0x67, 0x72, - 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x83, 0x02, 0x0a, 0x09, + 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xff, 0x01, 0x0a, 0x09, 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, - 0x63, 0x74, 0x65, 0x72, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x31, 0x0a, + 0x63, 0x74, 0x65, 0x72, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x33, 0x0a, 0x0a, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x73, 0x5f, 0x69, 0x6e, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x45, 0x70, - 0x69, 0x73, 0x6f, 0x64, 0x65, 0x52, 0x09, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x73, 0x49, 0x6e, - 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x6f, 0x6d, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x74, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x68, 0x6f, 0x6d, 0x65, 0x50, 0x6c, 0x61, 0x6e, 0x65, - 0x74, 0x12, 0x29, 0x0a, 0x10, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x75, 0x6e, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x72, 0x69, - 0x6d, 0x61, 0x72, 0x79, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x73, 0x74, 0x61, - 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, - 0x65, 0x22, 0x3e, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x07, 0x65, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, - 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x52, 0x07, 0x65, 0x70, 0x69, 0x73, 0x6f, 0x64, - 0x65, 0x22, 0x28, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x15, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, - 0x42, 0x05, 0xba, 0x43, 0x02, 0x08, 0x01, 0x52, 0x02, 0x69, 0x64, 0x22, 0x28, 0x0a, 0x0f, 0x47, - 0x65, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x15, - 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x05, 0xba, 0x43, 0x02, 0x08, - 0x01, 0x52, 0x02, 0x69, 0x64, 0x22, 0x12, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x42, 0x0a, 0x12, 0x4c, 0x69, 0x73, - 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x2c, 0x0a, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, - 0x61, 0x63, 0x74, 0x65, 0x72, 0x52, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x22, 0x42, 0x0a, - 0x12, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, - 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x52, 0x06, 0x64, 0x72, 0x6f, 0x69, 0x64, - 0x73, 0x2a, 0x1c, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, 0x0a, 0x05, 0x48, 0x55, 0x4d, - 0x41, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x44, 0x52, 0x4f, 0x49, 0x44, 0x10, 0x01, 0x2a, - 0x33, 0x0a, 0x07, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x12, 0x05, 0x0a, 0x01, 0x5f, 0x10, - 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x45, 0x57, 0x48, 0x4f, 0x50, 0x45, 0x10, 0x01, 0x12, 0x0a, - 0x0a, 0x06, 0x45, 0x4d, 0x50, 0x49, 0x52, 0x45, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x4a, 0x45, - 0x44, 0x49, 0x10, 0x03, 0x32, 0xaf, 0x03, 0x0a, 0x10, 0x53, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, - 0x72, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x45, 0x0a, 0x07, 0x47, 0x65, 0x74, - 0x48, 0x65, 0x72, 0x6f, 0x12, 0x19, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, - 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, - 0x61, 0x63, 0x74, 0x65, 0x72, 0x22, 0x09, 0xba, 0x43, 0x06, 0x12, 0x04, 0x68, 0x65, 0x72, 0x6f, - 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x12, 0x1a, 0x2e, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x75, 0x6d, 0x61, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, + 0x69, 0x73, 0x6f, 0x64, 0x65, 0x52, 0x0b, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x61, 0x6e, 0x63, + 0x65, 0x73, 0x12, 0x19, 0x0a, 0x0b, 0x68, 0x6f, 0x6d, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x6e, 0x65, + 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x6d, 0x65, 0x12, 0x29, 0x0a, + 0x10, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, + 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, + 0x72, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3e, 0x0a, + 0x0e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x2c, 0x0a, 0x07, 0x65, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x12, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x45, 0x70, 0x69, + 0x73, 0x6f, 0x64, 0x65, 0x52, 0x07, 0x65, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x22, 0x2d, 0x0a, + 0x0f, 0x47, 0x65, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1a, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x05, 0xba, 0x43, + 0x02, 0x08, 0x01, 0x52, 0x07, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x49, 0x44, 0x22, 0x2d, 0x0a, 0x0f, + 0x47, 0x65, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x05, 0xba, 0x43, 0x02, + 0x08, 0x01, 0x52, 0x07, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x49, 0x44, 0x22, 0x12, 0x0a, 0x10, 0x4c, + 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x42, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, + 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x52, 0x06, 0x68, 0x75, 0x6d, + 0x61, 0x6e, 0x73, 0x22, 0x42, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x64, 0x72, 0x6f, + 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x52, + 0x06, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x2a, 0x1c, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x09, 0x0a, 0x05, 0x48, 0x55, 0x4d, 0x41, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x44, 0x52, + 0x4f, 0x49, 0x44, 0x10, 0x01, 0x2a, 0x33, 0x0a, 0x07, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, + 0x12, 0x05, 0x0a, 0x01, 0x5f, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x45, 0x57, 0x48, 0x4f, + 0x50, 0x45, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x4d, 0x50, 0x49, 0x52, 0x45, 0x10, 0x02, + 0x12, 0x08, 0x0a, 0x04, 0x4a, 0x45, 0x44, 0x49, 0x10, 0x03, 0x32, 0xaf, 0x03, 0x0a, 0x10, 0x53, + 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x45, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x12, 0x19, 0x2e, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, + 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x22, 0x09, 0xba, 0x43, 0x06, + 0x12, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x48, 0x75, 0x6d, + 0x61, 0x6e, 0x12, 0x1a, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x47, + 0x65, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, + 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, + 0x63, 0x74, 0x65, 0x72, 0x22, 0x0a, 0xba, 0x43, 0x07, 0x12, 0x05, 0x68, 0x75, 0x6d, 0x61, 0x6e, + 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x12, 0x1a, 0x2e, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x72, 0x6f, 0x69, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x22, 0x0a, - 0xba, 0x43, 0x07, 0x12, 0x05, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x12, 0x48, 0x0a, 0x08, 0x47, 0x65, - 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x12, 0x1a, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, - 0x72, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x43, - 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x22, 0x0a, 0xba, 0x43, 0x07, 0x12, 0x05, 0x64, - 0x72, 0x6f, 0x69, 0x64, 0x12, 0x5f, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x75, 0x6d, 0x61, - 0x6e, 0x73, 0x12, 0x1b, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x4c, - 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, - 0xba, 0x43, 0x12, 0x12, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x22, 0x08, 0x12, 0x06, 0x68, - 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x12, 0x5f, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x72, 0x6f, - 0x69, 0x64, 0x73, 0x12, 0x1b, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, - 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1d, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x4c, 0x69, 0x73, - 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x15, 0xba, 0x43, 0x12, 0x12, 0x06, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x22, 0x08, 0x12, 0x06, - 0x64, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x42, 0x4a, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x65, 0x68, 0x65, 0x63, 0x68, 0x6b, 0x61, 0x2f, 0x67, - 0x72, 0x70, 0x63, 0x2d, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2d, 0x67, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x73, 0x74, 0x61, 0x72, - 0x77, 0x61, 0x72, 0x73, 0x2f, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x77, 0x61, - 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0xba, 0x43, 0x07, 0x12, 0x05, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x12, 0x5f, 0x0a, 0x0a, 0x4c, 0x69, + 0x73, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x12, 0x1b, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, + 0x77, 0x61, 0x72, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, 0x72, + 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0xba, 0x43, 0x12, 0x12, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, + 0x73, 0x22, 0x08, 0x12, 0x06, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x73, 0x12, 0x5f, 0x0a, 0x0a, 0x4c, + 0x69, 0x73, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x12, 0x1b, 0x2e, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x77, 0x61, 0x72, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x73, 0x74, 0x61, 0x72, 0x74, 0x77, 0x61, + 0x72, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0xba, 0x43, 0x12, 0x12, 0x06, 0x64, 0x72, 0x6f, 0x69, + 0x64, 0x73, 0x22, 0x08, 0x12, 0x06, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x73, 0x42, 0x4a, 0x5a, 0x48, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x65, 0x68, 0x65, + 0x63, 0x68, 0x6b, 0x61, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, + 0x6c, 0x2d, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x77, 0x61, 0x72, 0x73, 0x2f, 0x73, 0x70, 0x65, 0x63, 0x2f, + 0x73, 0x74, 0x61, 0x72, 0x77, 0x61, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/go.mod b/go.mod index 64287ec..09809ee 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/friendsofgo/graphiql v0.2.2 + github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 github.com/graphql-go/graphql v0.8.0 github.com/iancoleman/strcase v0.2.0 diff --git a/go.sum b/go.sum index 8498550..c4ff577 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/friendsofgo/graphiql v0.2.2 h1:ccnuxpjgIkB+Lr9YB2ZouiZm7wvciSfqwpa9ugWzmn0= github.com/friendsofgo/graphiql v0.2.2/go.mod h1:8Y2kZ36AoTGWs78+VRpvATyt3LJBx0SZXmay80ZTRWo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -53,6 +55,8 @@ github.com/graphql-go/graphql v0.8.0/go.mod h1:nKiHzRM0qopJEwCITUuIsxk9PlVlwIiiI github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -66,19 +70,26 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/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-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -88,6 +99,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -103,6 +116,11 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml index 24f4dd3..4a4cd5c 100644 --- a/proto/buf.gen.yaml +++ b/proto/buf.gen.yaml @@ -5,6 +5,7 @@ managed: default: github.com/alehechka/grpc-graphql-gateway/proto/gen/go plugins: - remote: buf.build/protocolbuffers/plugins/go:v1.28.0-1 + # - name: go out: gen/go opt: - paths=source_relative diff --git a/proto/gen/go/graphql/graphql.pb.go b/proto/gen/go/graphql/graphql.pb.go index 904624a..15168bb 100644 --- a/proto/gen/go/graphql/graphql.pb.go +++ b/proto/gen/go/graphql/graphql.pb.go @@ -420,7 +420,10 @@ type GraphqlField struct { // If true, this field is required. Required bool `protobuf:"varint,1,opt,name=required,proto3" json:"required,omitempty"` - // Use as other field name (not recommend) + // DEPRECATED + // Use default `json_name` to supply custom name for graphql fields + // + // Deprecated: Do not use. Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` // Define default value on input. Default string `protobuf:"bytes,3,opt,name=default,proto3" json:"default,omitempty"` @@ -469,6 +472,7 @@ func (x *GraphqlField) GetRequired() bool { return false } +// Deprecated: Do not use. func (x *GraphqlField) GetName() string { if x != nil { return x.Name @@ -570,44 +574,44 @@ var file_graphql_graphql_proto_rawDesc = []byte{ 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6c, 0x75, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x6c, 0x75, 0x63, 0x6b, - 0x22, 0x88, 0x01, 0x0a, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x46, 0x69, 0x65, 0x6c, + 0x22, 0x8c, 0x01, 0x0a, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6f, - 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x6f, 0x6d, 0x69, 0x74, 0x12, - 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x72, 0x2a, 0x34, 0x0a, 0x0b, 0x47, - 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, 0x0a, 0x05, 0x51, 0x55, - 0x45, 0x52, 0x59, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x4d, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, - 0x4e, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53, 0x4f, 0x4c, 0x56, 0x45, 0x52, 0x10, - 0x02, 0x3a, 0x53, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1f, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb7, 0x08, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2e, 0x47, - 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x07, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x3a, 0x4b, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x12, - 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb7, - 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2e, - 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x05, 0x66, 0x69, - 0x65, 0x6c, 0x64, 0x3a, 0x4f, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x1e, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb7, 0x08, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2e, 0x47, - 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x52, 0x06, 0x73, 0x63, - 0x68, 0x65, 0x6d, 0x61, 0x42, 0x97, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x72, 0x61, - 0x70, 0x68, 0x71, 0x6c, 0x42, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x61, 0x6c, 0x65, 0x68, 0x65, 0x63, 0x68, 0x6b, 0x61, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, - 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2d, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x67, 0x72, 0x61, - 0x70, 0x68, 0x71, 0x6c, 0xa2, 0x02, 0x03, 0x47, 0x58, 0x58, 0xaa, 0x02, 0x07, 0x47, 0x72, 0x61, - 0x70, 0x68, 0x71, 0x6c, 0xca, 0x02, 0x07, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0xe2, 0x02, - 0x13, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x07, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x16, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, + 0x12, 0x0a, 0x04, 0x6f, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x6f, + 0x6d, 0x69, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x72, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x72, 0x2a, + 0x34, 0x0a, 0x0b, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x09, + 0x0a, 0x05, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x4d, 0x55, 0x54, + 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53, 0x4f, 0x4c, + 0x56, 0x45, 0x52, 0x10, 0x02, 0x3a, 0x53, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x18, 0xb7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, + 0x71, 0x6c, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x3a, 0x4b, 0x0a, 0x05, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0xb7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x67, 0x72, 0x61, 0x70, + 0x68, 0x71, 0x6c, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x46, 0x69, 0x65, 0x6c, 0x64, + 0x52, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x3a, 0x4f, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, + 0x61, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x18, 0xb7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, + 0x71, 0x6c, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, + 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x42, 0x97, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, + 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x42, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, + 0x6c, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x65, 0x68, 0x65, 0x63, 0x68, 0x6b, 0x61, 0x2f, 0x67, + 0x72, 0x70, 0x63, 0x2d, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x2d, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, + 0x2f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0xa2, 0x02, 0x03, 0x47, 0x58, 0x58, 0xaa, 0x02, + 0x07, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0xca, 0x02, 0x07, 0x47, 0x72, 0x61, 0x70, 0x68, + 0x71, 0x6c, 0xe2, 0x02, 0x13, 0x47, 0x72, 0x61, 0x70, 0x68, 0x71, 0x6c, 0x5c, 0x47, 0x50, 0x42, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x07, 0x47, 0x72, 0x61, 0x70, 0x68, + 0x71, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/grpc-graphql-gateway/graphql/graphql.proto b/proto/grpc-graphql-gateway/graphql/graphql.proto index d1ec613..c2e9260 100644 --- a/proto/grpc-graphql-gateway/graphql/graphql.proto +++ b/proto/grpc-graphql-gateway/graphql/graphql.proto @@ -161,8 +161,9 @@ enum GraphqlType { message GraphqlField { // If true, this field is required. bool required = 1; - // Use as other field name (not recommend) - string name = 2; + // DEPRECATED + // Use default `json_name` to supply custom name for graphql fields + string name = 2 [deprecated = true]; // Define default value on input. string default = 3; // Omit this field from graphql definition diff --git a/protoc-gen-graphql/README.md b/protoc-gen-graphql/README.md index 2059f06..8eed07d 100644 --- a/protoc-gen-graphql/README.md +++ b/protoc-gen-graphql/README.md @@ -22,7 +22,7 @@ This plugin accepts some compile arguments: - `--graphql_out=verbose`: verbose debug output - `--graphql_out=exclude=[regex]`: exclude generation package with regexp -- `--graphql_out=field_camel`: all graphql field name transform to lower-camel-case +- `--graphql_out=field_proto`: by default all graphql fields will use `json_name` as the field name, providing this option will instead use the raw `protobuf` name. All arguments can be provide by splitting comma. diff --git a/protoc-gen-graphql/generator/generator.go b/protoc-gen-graphql/generator/generator.go index 5b2827b..55c1ea2 100644 --- a/protoc-gen-graphql/generator/generator.go +++ b/protoc-gen-graphql/generator/generator.go @@ -326,13 +326,13 @@ func (g *Generator) analyzeService(f *spec.File, s *spec.Service) error { switch m.Schema.GetType() { case graphql.GraphqlType_QUERY, graphql.GraphqlType_RESOLVER: - q := spec.NewQuery(m, input, output, g.args.FieldCamelCase) + q := spec.NewQuery(m, input, output, g.args.FieldProtoName) if err := g.analyzeQuery(f, q); err != nil { return err } s.Queries = append(s.Queries, q) case graphql.GraphqlType_MUTATION: - mu := spec.NewMutation(m, input, output, g.args.FieldCamelCase) + mu := spec.NewMutation(m, input, output, g.args.FieldProtoName) if err := g.analyzeMutation(f, mu); err != nil { return err } diff --git a/protoc-gen-graphql/main.go b/protoc-gen-graphql/main.go index ca9cb97..e52ad5b 100644 --- a/protoc-gen-graphql/main.go +++ b/protoc-gen-graphql/main.go @@ -64,8 +64,8 @@ func main() { return } - if args.FieldCamelCase { - log.Println("[INFO] field_camel option is provided. All type fields are transform to camelcase.") + if args.FieldProtoName { + log.Println("[INFO] field_proto option is provided. All type fields will use the `protobuf` name tag.") } // We're dealing with each descriptors to out wrapper struct @@ -73,7 +73,7 @@ func main() { var files []*spec.File for _, f := range req.GetProtoFile() { files = append(files, spec.NewFile(f, &spec.FileConfig{ - IsCamel: args.FieldCamelCase, + UseProtoName: args.FieldProtoName, CompilerVersion: req.GetCompilerVersion(), PluginVersion: version, })) diff --git a/protoc-gen-graphql/spec/enum.go b/protoc-gen-graphql/spec/enum.go index 3fc1af1..f215abf 100644 --- a/protoc-gen-graphql/spec/enum.go +++ b/protoc-gen-graphql/spec/enum.go @@ -22,7 +22,7 @@ func NewEnum( d *descriptor.EnumDescriptorProto, f *File, prefix []string, - isCamel bool, + useProtoName bool, paths ...int, ) *Enum { @@ -38,7 +38,7 @@ func NewEnum( for i, v := range d.GetValue() { ps := make([]int, len(paths)) copy(ps, paths) - e.values = append(e.values, NewEnumValue(v, f, isCamel, append(ps, 2, i)...)) + e.values = append(e.values, NewEnumValue(v, f, useProtoName, append(ps, 2, i)...)) } return e } diff --git a/protoc-gen-graphql/spec/enum_value.go b/protoc-gen-graphql/spec/enum_value.go index 727d87d..f366e4c 100644 --- a/protoc-gen-graphql/spec/enum_value.go +++ b/protoc-gen-graphql/spec/enum_value.go @@ -9,22 +9,22 @@ type EnumValue struct { descriptor *descriptor.EnumValueDescriptorProto *File - paths []int - isCamel bool + paths []int + useProtoName bool } func NewEnumValue( d *descriptor.EnumValueDescriptorProto, f *File, - isCamel bool, + useProtoName bool, paths ...int, ) *EnumValue { return &EnumValue{ - descriptor: d, - File: f, - isCamel: isCamel, - paths: paths, + descriptor: d, + File: f, + useProtoName: useProtoName, + paths: paths, } } @@ -40,9 +40,9 @@ func (e *EnumValue) Name() string { return e.descriptor.GetName() } -func (e *EnumValue) IsCamel() bool { +func (e *EnumValue) UseProtoName() bool { if e != nil { - return e.isCamel + return e.useProtoName } return false } diff --git a/protoc-gen-graphql/spec/field.go b/protoc-gen-graphql/spec/field.go index dfc5385..389ced3 100644 --- a/protoc-gen-graphql/spec/field.go +++ b/protoc-gen-graphql/spec/field.go @@ -7,7 +7,6 @@ import ( graphql "github.com/alehechka/grpc-graphql-gateway/proto/gen/go/graphql" "github.com/golang/protobuf/proto" descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" - "github.com/iancoleman/strcase" ) // Field spec wraps FieldDescriptorProto with keeping file info @@ -20,14 +19,14 @@ type Field struct { DependType interface{} IsCyclic bool - isCamel bool + useProtoName bool forceRequired bool } func NewField( d *descriptor.FieldDescriptorProto, f *File, - isCamel bool, + useProtoName bool, paths ...int, ) *Field { @@ -41,11 +40,11 @@ func NewField( } return &Field{ - descriptor: d, - Option: o, - File: f, - paths: paths, - isCamel: isCamel, + descriptor: d, + Option: o, + File: f, + paths: paths, + useProtoName: useProtoName, } } @@ -65,10 +64,10 @@ func (f *Field) setRequiredField() { } func (f *Field) FieldName() string { - if f.isCamel { - return strcase.ToLowerCamel(f.Name()) + if f.useProtoName { + return f.Name() } - return f.Name() + return *f.descriptor.JsonName } func (f *Field) Type() descriptor.FieldDescriptorProto_Type { diff --git a/protoc-gen-graphql/spec/file.go b/protoc-gen-graphql/spec/file.go index b4f934f..332a7bf 100644 --- a/protoc-gen-graphql/spec/file.go +++ b/protoc-gen-graphql/spec/file.go @@ -20,21 +20,21 @@ type File struct { services []*Service enums []*Enum - isCamel bool + useProtoName bool compilerVersion *plugin.Version pluginVersion string } type FileConfig struct { - IsCamel bool + UseProtoName bool CompilerVersion *plugin.Version PluginVersion string } -func (c *FileConfig) GetIsCamel() bool { +func (c *FileConfig) GetUseProtoName() bool { if c != nil { - return c.IsCamel + return c.UseProtoName } return false } @@ -64,10 +64,10 @@ func NewFile( descriptor: d, comments: makeComments(d), - services: make([]*Service, 0), - messages: make([]*Message, 0), - enums: make([]*Enum, 0), - isCamel: config.GetIsCamel(), + services: make([]*Service, 0), + messages: make([]*Message, 0), + enums: make([]*Enum, 0), + useProtoName: config.GetUseProtoName(), } for i, s := range d.GetService() { f.services = append(f.services, NewService(s, f, 6, i)) @@ -76,7 +76,7 @@ func NewFile( f.messages = append(f.messages, f.messagesRecursive(m, []string{}, 4, i)...) } for i, e := range d.GetEnumType() { - f.enums = append(f.enums, NewEnum(e, f, []string{}, f.isCamel, 5, i)) + f.enums = append(f.enums, NewEnum(e, f, []string{}, f.useProtoName, 5, i)) } return f } @@ -94,7 +94,7 @@ func (f *File) Enums() []*Enum { } func (f *File) messagesRecursive(d *descriptor.DescriptorProto, prefix []string, paths ...int) []*Message { - m := NewMessage(d, f, prefix, f.isCamel, paths...) + m := NewMessage(d, f, prefix, f.useProtoName, paths...) // If message is map_entry, assign all fields as "required" if opt := d.GetOptions(); opt != nil && opt.GetMapEntry() { @@ -108,7 +108,7 @@ func (f *File) messagesRecursive(d *descriptor.DescriptorProto, prefix []string, for i, e := range d.GetEnumType() { p := make([]int, len(paths)) copy(p, paths) - f.enums = append(f.enums, NewEnum(e, f, prefix, f.isCamel, append(p, 5, i)...)) + f.enums = append(f.enums, NewEnum(e, f, prefix, f.useProtoName, append(p, 5, i)...)) } for i, m := range d.GetNestedType() { diff --git a/protoc-gen-graphql/spec/message.go b/protoc-gen-graphql/spec/message.go index b4cbbd4..c6bcab1 100644 --- a/protoc-gen-graphql/spec/message.go +++ b/protoc-gen-graphql/spec/message.go @@ -25,7 +25,7 @@ func NewMessage( d *descriptor.DescriptorProto, f *File, prefix []string, - isCamel bool, + useProtoName bool, paths ...int, ) *Message { @@ -41,7 +41,7 @@ func NewMessage( for i, field := range d.GetField() { ps := make([]int, len(paths)) copy(ps, paths) - ff := NewField(field, f, isCamel, append(ps, 2, i)...) + ff := NewField(field, f, useProtoName, append(ps, 2, i)...) if !ff.IsOmit() { m.fields = append(m.fields, ff) } diff --git a/protoc-gen-graphql/spec/mutation.go b/protoc-gen-graphql/spec/mutation.go index cb3a8d6..fa9a00c 100644 --- a/protoc-gen-graphql/spec/mutation.go +++ b/protoc-gen-graphql/spec/mutation.go @@ -15,20 +15,20 @@ type Mutation struct { Input *Message Output *Message - isCamel bool + useProtoName bool } -func NewMutation(m *Method, input, output *Message, isCamel bool) *Mutation { +func NewMutation(m *Method, input, output *Message, useProtoName bool) *Mutation { return &Mutation{ - Method: m, - Input: input, - Output: output, - isCamel: isCamel, + Method: m, + Input: input, + Output: output, + useProtoName: useProtoName, } } -func (m *Mutation) IsCamel() bool { - return m.isCamel +func (m *Mutation) UseProtoName() bool { + return m.useProtoName } func (m *Mutation) MutationName() string { diff --git a/protoc-gen-graphql/spec/params.go b/protoc-gen-graphql/spec/params.go index 5fb89e0..989b1c3 100644 --- a/protoc-gen-graphql/spec/params.go +++ b/protoc-gen-graphql/spec/params.go @@ -16,7 +16,7 @@ type Params struct { QueryOut string Excludes []*regexp.Regexp Verbose bool - FieldCamelCase bool + FieldProtoName bool Paths string } @@ -47,8 +47,8 @@ func NewParams(p string) (*Params, error) { return nil, errors.New("failed to compile regex for exclude argument " + kv[1]) } params.Excludes = append(params.Excludes, regex) - case "field_camel": - params.FieldCamelCase = true + case "field_proto": + params.FieldProtoName = true case "paths": if len(kv) == 1 { return nil, errors.New("argument " + kv[0] + " must have value") diff --git a/protoc-gen-graphql/spec/query.go b/protoc-gen-graphql/spec/query.go index 0ea69be..af7fa21 100644 --- a/protoc-gen-graphql/spec/query.go +++ b/protoc-gen-graphql/spec/query.go @@ -17,15 +17,15 @@ type Query struct { Input *Message Output *Message - isCamel bool + useProtoName bool } -func NewQuery(m *Method, input, output *Message, isCamel bool) *Query { +func NewQuery(m *Method, input, output *Message, useProtoName bool) *Query { return &Query{ - Method: m, - Input: input, - Output: output, - isCamel: isCamel, + Method: m, + Input: input, + Output: output, + useProtoName: useProtoName, } } @@ -33,8 +33,8 @@ func (q *Query) IsResolver() bool { return q.Schema.GetType() == graphql.GraphqlType_RESOLVER } -func (q *Query) IsCamel() bool { - return q.isCamel +func (q *Query) UseProtoName() bool { + return q.useProtoName } func (q *Query) QueryName() string { diff --git a/protoc-gen-graphql/template/template.go b/protoc-gen-graphql/template/template.go index 2bd93d6..1b37ba2 100644 --- a/protoc-gen-graphql/template/template.go +++ b/protoc-gen-graphql/template/template.go @@ -50,7 +50,7 @@ func Gql__enum_{{ .Name }}() *graphql.Enum { {{- if .Comment }} Description: ` + "`" + `{{ .Comment }}` + "`" + `, {{- end }} - Value: {{ if .IsCamel }}int32{{ else }}{{ $enum.Name }}{{ end }}({{ .Number }}), + Value: {{ if .UseProtoName }}{{ $enum.Name }}{{ else }}int32{{ end }}({{ .Number }}), }, {{- end }} }, @@ -124,9 +124,9 @@ func Gql__type_{{ .TypeName }}() *graphql.Object { }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req {{ $query.InputType }} - if err := runtime.MarshalRequest(p.Source, &req, {{ if $query.IsCamel }}true{{ else }}false{{ end }}); err != nil { + if err := runtime.MarshalRequest(p.Source, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal resolver source for {{ $query.QueryName }}") - } else if err = runtime.MarshalRequest(p.Args, &req, {{ if $query.IsCamel }}true{{ else }}false{{ end }}); err != nil { + } else if err = runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal resolver request for {{ $query.QueryName }}") } {{ $s := index $.Services 0 }} @@ -142,16 +142,16 @@ func Gql__type_{{ .TypeName }}() *graphql.Object { return nil, errors.Wrap(err, "Failed to call RPC {{ $query.Method.Name }}") } {{- if $query.IsPluckResponse }} - {{- if $query.IsCamel }} - return runtime.MarshalResponse(resp.Get{{ $query.PluckResponseFieldName }}()), nil - {{- else }} + {{- if $query.UseProtoName }} return resp.Get{{ $query.PluckResponseFieldName }}(), nil + {{- else }} + return runtime.MarshalResponse(resp.Get{{ $query.PluckResponseFieldName }}()), nil {{- end }} {{- else }} - {{- if $query.IsCamel }} - return runtime.MarshalResponse(resp), nil - {{- else }} + {{- if $query.UseProtoName }} return resp, nil + {{- else }} + return runtime.MarshalResponse(resp), nil {{- end }} {{- end }} }, @@ -278,7 +278,7 @@ func (x *graphql__resolver_{{ $service.Name }}) GetQueries(conn *grpc.ClientConn }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req {{ .InputType }} - if err := runtime.MarshalRequest(p.Args, &req, {{ if .IsCamel }}true{{ else }}false{{ end }}); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { return nil, errors.Wrap(err, "Failed to marshal request for {{ .QueryName }}") } client := New{{ .Method.Service.Name }}Client(conn) @@ -287,16 +287,16 @@ func (x *graphql__resolver_{{ $service.Name }}) GetQueries(conn *grpc.ClientConn return nil, errors.Wrap(err, "Failed to call RPC {{ .Method.Name }}") } {{- if .IsPluckResponse }} - {{- if .IsCamel }} - return runtime.MarshalResponse(resp.Get{{ .PluckResponseFieldName }}()), nil - {{- else }} + {{- if .UseProtoName }} return resp.Get{{ .PluckResponseFieldName }}(), nil + {{- else }} + return runtime.MarshalResponse(resp.Get{{ .PluckResponseFieldName }}()), nil {{- end }} {{- else }} - {{- if .IsCamel }} - return runtime.MarshalResponse(resp), nil - {{- else }} + {{- if .UseProtoName }} return resp, nil + {{- else }} + return runtime.MarshalResponse(resp), nil {{- end }} {{- end }} }, @@ -337,9 +337,9 @@ func (x *graphql__resolver_{{ $service.Name }}) GetMutations(conn *grpc.ClientCo Resolve: func(p graphql.ResolveParams) (interface{}, error) { var req {{ .InputType }} {{- if .InputName }} - if err := runtime.MarshalRequest(p.Args["{{ .InputName }}"], &req, {{ if .IsCamel }}true{{ else }}false{{ end }}); err != nil { + if err := runtime.MarshalRequest(p.Args["{{ .InputName }}"], &req); err != nil { {{- else }} - if err := runtime.MarshalRequest(p.Args, &req, {{ if .IsCamel }}true{{ else }}false{{ end }}); err != nil { + if err := runtime.MarshalRequest(p.Args, &req); err != nil { {{- end }} return nil, errors.Wrap(err, "Failed to marshal request for {{ .MutationName }}") } @@ -349,16 +349,16 @@ func (x *graphql__resolver_{{ $service.Name }}) GetMutations(conn *grpc.ClientCo return nil, errors.Wrap(err, "Failed to call RPC {{ .Method.Name }}") } {{- if .IsPluckResponse }} - {{- if .IsCamel }} - return runtime.MarshalResponse(resp.Get{{ .PluckResponseFieldName }}()), nil - {{- else }} + {{- if .UseProtoName }} return resp.Get{{ .PluckResponseFieldName }}(), nil + {{- else }} + return runtime.MarshalResponse(resp.Get{{ .PluckResponseFieldName }}()), nil {{- end }} {{- else }} - {{- if .IsCamel }} - return runtime.MarshalResponse(resp), nil - {{- else }} + {{- if .UseProtoName }} return resp, nil + {{- else }} + return runtime.MarshalResponse(resp), nil {{- end }} {{- end }} }, diff --git a/runtime/request.go b/runtime/request.go index 9b71ac9..bc431db 100644 --- a/runtime/request.go +++ b/runtime/request.go @@ -1,13 +1,14 @@ package runtime import ( - "errors" - + "bytes" "encoding/json" + "errors" "io/ioutil" "net/http" - "github.com/iancoleman/strcase" + "github.com/golang/protobuf/jsonpb" + "google.golang.org/protobuf/runtime/protoiface" ) type GraphqlRequest struct { @@ -44,45 +45,12 @@ func parseRequest(r *http.Request) (*GraphqlRequest, error) { } // MarshalRequest marshals graphql request arguments to gRPC request message -func MarshalRequest(args, v interface{}, isCamel bool) error { - if args == nil { - return errors.New("Resolved params should be non-nil") - } - m, ok := args.(map[string]interface{}) // graphql.ResolveParams or nested object - if !ok { - return errors.New("Failed to type conversion of map[string]interface{}") - } - if isCamel { - m = toLowerCaseKeys(m) - } - buf, err := json.Marshal(m) - if err != nil { - return err - } - return json.Unmarshal(buf, &v) -} +func MarshalRequest(args map[string]interface{}, message protoiface.MessageV1) error { + buf := new(bytes.Buffer) -// Convert to lower case keyname string -func toLowerCaseKeys(args map[string]interface{}) map[string]interface{} { - lc := make(map[string]interface{}) - for k, v := range args { - lc[strcase.ToSnake(k)] = marshal(v) + if err := json.NewEncoder(buf).Encode(args); err != nil { + return err } - return lc -} -// marshals interface recursively -func marshal(v interface{}) interface{} { - switch t := v.(type) { - case map[string]interface{}: - return toLowerCaseKeys(t) - case []interface{}: - ret := make([]interface{}, len(t)) - for i, si := range t { - ret[i] = marshal(si) - } - return ret - default: - return t - } + return jsonpb.Unmarshal(buf, message) } diff --git a/runtime/response.go b/runtime/response.go index 8b66319..416b082 100644 --- a/runtime/response.go +++ b/runtime/response.go @@ -3,8 +3,6 @@ package runtime import ( "reflect" "strings" - - "github.com/iancoleman/strcase" ) func derefValue(v reflect.Value) reflect.Value { @@ -59,14 +57,11 @@ func marshalStruct(v reflect.Value) map[string]interface{} { t := v.Type() for i := 0; i < t.NumField(); i++ { - // If "json" tag is not set in struct field, it's not related to response field - // So we can skip marshaling - tag := t.Field(i).Tag.Get("json") - if tag == "" { + name := getTagName(t.Field(i).Tag) + if len(name) == 0 { continue } - name := strcase.ToLowerCamel(strings.TrimSuffix(tag, ",omitempty")) vv := derefValue(v.Field(i)) switch vv.Kind() { @@ -83,6 +78,24 @@ func marshalStruct(v reflect.Value) map[string]interface{} { return ret } +func getTagName(tag reflect.StructTag) (name string) { + + protoTag := tag.Get("protobuf") + options := strings.Split(protoTag, ",") + + for _, option := range options { + if strings.HasPrefix(option, "name") { + name = option[5:] + } + if strings.HasPrefix(option, "json") { + name = option[5:] + break + } + } + + return +} + type mapValue struct { Key interface{} `json:"key"` Value interface{} `json:"value"` diff --git a/runtime/response_test.go b/runtime/response_test.go index ab1a30e..c0302b8 100644 --- a/runtime/response_test.go +++ b/runtime/response_test.go @@ -7,29 +7,29 @@ import ( ) type exampleStruct struct { - UserId int64 `json:"user_id,omitempty"` - Name string `json:"name,omitempty"` + UserId int64 `protobuf:"name=user_id,json=userId" json:"user_id,omitempty"` + Name string `protobuf:"name=name" json:"name,omitempty"` - TestInt int `json:"test_int,omitempty"` - TestInt32 int32 `json:"test_int32,omitempty"` - TestInt64 int64 `json:"test_int64,omitempty"` + TestInt int `protobuf:"name=test_int,json=testInt" json:"test_int,omitempty"` + TestInt32 int32 `protobuf:"name=test_int32,json=testInt32" json:"test_int32,omitempty"` + TestInt64 int64 `protobuf:"name=test_int64,json=testInt64" json:"test_int64,omitempty"` - TestUint uint `json:"test_uint,omitempty"` - TestUint32 uint32 `json:"test_uint32,omitempty"` - TestUint64 uint64 `json:"test_uint64,omitempty"` + TestUint uint `protobuf:"name=test_uint,json=testUint" json:"test_uint,omitempty"` + TestUint32 uint32 `protobuf:"name=test_uint32,json=testUint32" json:"test_uint32,omitempty"` + TestUint64 uint64 `protobuf:"name=test_uint64,json=testUint64" json:"test_uint64,omitempty"` - TestFloat32 float32 `json:"test_float32,omitempty"` - TestFloat64 float64 `json:"test_float64,omitempty"` + TestFloat32 float32 `protobuf:"name=test_float32,json=testFloat32" json:"test_float32,omitempty"` + TestFloat64 float64 `protobuf:"name=test_float64,json=testFloat64" json:"test_float64,omitempty"` - TestBool bool `json:"test_bool,omitempty"` + TestBool bool `protobuf:"name=test_bool,json=testBool" json:"test_bool,omitempty"` - SubStruct *exampleSubStruct `json:"sub_struct,omitempty"` - SubSlice []*exampleSubStruct `json:"sub_slice,omitempty"` - SubMap map[string]int64 `json:"sub_map,omitempty"` + SubStruct *exampleSubStruct `protobuf:"name=sub_struct,json=subStruct" json:"sub_struct,omitempty"` + SubSlice []*exampleSubStruct `protobuf:"name=sub_slice,json=subSlice" json:"sub_slice,omitempty"` + SubMap map[string]int64 `protobuf:"name=sub_map,json=subMap" json:"sub_map,omitempty"` } type exampleSubStruct struct { - SomeData string `json:"some_data,omitempty"` + SomeData string `protobuf:"name=some_data,json=someData" json:"some_data,omitempty"` } func assertMap(t *testing.T, actual map[string]interface{}, expects map[string]interface{}) { diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile new file mode 100644 index 0000000..0776990 --- /dev/null +++ b/runtime/tests/Makefile @@ -0,0 +1,5 @@ +build: + protoc \ + -I. \ + --go_out=:./ \ + request.proto \ No newline at end of file diff --git a/runtime/tests/request.pb.go b/runtime/tests/request.pb.go new file mode 100644 index 0000000..e15adc7 --- /dev/null +++ b/runtime/tests/request.pb.go @@ -0,0 +1,339 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.21.4 +// source: request.proto + +package tests + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type A struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StringValue string `protobuf:"bytes,1,opt,name=string_value,json=stringValue,proto3" json:"string_value,omitempty"` + IntValue int64 `protobuf:"varint,2,opt,name=int_value,json=intValue,proto3" json:"int_value,omitempty"` + StringSlice []string `protobuf:"bytes,3,rep,name=string_slice,json=stringSlice,proto3" json:"string_slice,omitempty"` + NestedStruct *B `protobuf:"bytes,4,opt,name=nested_struct,json=nestedStruct,proto3" json:"nested_struct,omitempty"` + StructSlice []*C `protobuf:"bytes,5,rep,name=struct_slice,json=structSlice,proto3" json:"struct_slice,omitempty"` +} + +func (x *A) Reset() { + *x = A{} + if protoimpl.UnsafeEnabled { + mi := &file_request_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *A) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*A) ProtoMessage() {} + +func (x *A) ProtoReflect() protoreflect.Message { + mi := &file_request_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use A.ProtoReflect.Descriptor instead. +func (*A) Descriptor() ([]byte, []int) { + return file_request_proto_rawDescGZIP(), []int{0} +} + +func (x *A) GetStringValue() string { + if x != nil { + return x.StringValue + } + return "" +} + +func (x *A) GetIntValue() int64 { + if x != nil { + return x.IntValue + } + return 0 +} + +func (x *A) GetStringSlice() []string { + if x != nil { + return x.StringSlice + } + return nil +} + +func (x *A) GetNestedStruct() *B { + if x != nil { + return x.NestedStruct + } + return nil +} + +func (x *A) GetStructSlice() []*C { + if x != nil { + return x.StructSlice + } + return nil +} + +type B struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StringValue string `protobuf:"bytes,1,opt,name=string_value,json=valueString,proto3" json:"string_value,omitempty"` + IntValue int64 `protobuf:"varint,2,opt,name=int_value,json=valueInt,proto3" json:"int_value,omitempty"` + StringSlice []string `protobuf:"bytes,3,rep,name=string_slice,json=sliceString,proto3" json:"string_slice,omitempty"` +} + +func (x *B) Reset() { + *x = B{} + if protoimpl.UnsafeEnabled { + mi := &file_request_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *B) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*B) ProtoMessage() {} + +func (x *B) ProtoReflect() protoreflect.Message { + mi := &file_request_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use B.ProtoReflect.Descriptor instead. +func (*B) Descriptor() ([]byte, []int) { + return file_request_proto_rawDescGZIP(), []int{1} +} + +func (x *B) GetStringValue() string { + if x != nil { + return x.StringValue + } + return "" +} + +func (x *B) GetIntValue() int64 { + if x != nil { + return x.IntValue + } + return 0 +} + +func (x *B) GetStringSlice() []string { + if x != nil { + return x.StringSlice + } + return nil +} + +type C struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StringValue string `protobuf:"bytes,1,opt,name=string_value,json=stringValue,proto3" json:"string_value,omitempty"` + IntValue int64 `protobuf:"varint,2,opt,name=int_value,json=intValue,proto3" json:"int_value,omitempty"` +} + +func (x *C) Reset() { + *x = C{} + if protoimpl.UnsafeEnabled { + mi := &file_request_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *C) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*C) ProtoMessage() {} + +func (x *C) ProtoReflect() protoreflect.Message { + mi := &file_request_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use C.ProtoReflect.Descriptor instead. +func (*C) Descriptor() ([]byte, []int) { + return file_request_proto_rawDescGZIP(), []int{2} +} + +func (x *C) GetStringValue() string { + if x != nil { + return x.StringValue + } + return "" +} + +func (x *C) GetIntValue() int64 { + if x != nil { + return x.IntValue + } + return 0 +} + +var File_request_proto protoreflect.FileDescriptor + +var file_request_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0xb6, 0x01, 0x0a, 0x01, 0x41, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x69, 0x6e, 0x74, + 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, + 0x73, 0x6c, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x53, 0x6c, 0x69, 0x63, 0x65, 0x12, 0x27, 0x0a, 0x0d, 0x6e, 0x65, 0x73, 0x74, + 0x65, 0x64, 0x5f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x02, 0x2e, 0x42, 0x52, 0x0c, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x53, 0x74, 0x72, 0x75, 0x63, + 0x74, 0x12, 0x25, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x5f, 0x73, 0x6c, 0x69, 0x63, + 0x65, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x02, 0x2e, 0x43, 0x52, 0x0b, 0x73, 0x74, 0x72, + 0x75, 0x63, 0x74, 0x53, 0x6c, 0x69, 0x63, 0x65, 0x22, 0x66, 0x0a, 0x01, 0x42, 0x12, 0x21, 0x0a, + 0x0c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x49, 0x6e, 0x74, 0x12, 0x21, 0x0a, + 0x0c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x6c, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x6c, 0x69, 0x63, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x22, 0x43, 0x0a, 0x01, 0x43, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x69, 0x6e, 0x74, + 0x56, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x74, 0x65, 0x73, 0x74, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_request_proto_rawDescOnce sync.Once + file_request_proto_rawDescData = file_request_proto_rawDesc +) + +func file_request_proto_rawDescGZIP() []byte { + file_request_proto_rawDescOnce.Do(func() { + file_request_proto_rawDescData = protoimpl.X.CompressGZIP(file_request_proto_rawDescData) + }) + return file_request_proto_rawDescData +} + +var file_request_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_request_proto_goTypes = []interface{}{ + (*A)(nil), // 0: A + (*B)(nil), // 1: B + (*C)(nil), // 2: C +} +var file_request_proto_depIdxs = []int32{ + 1, // 0: A.nested_struct:type_name -> B + 2, // 1: A.struct_slice:type_name -> C + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_request_proto_init() } +func file_request_proto_init() { + if File_request_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_request_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*A); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_request_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*B); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_request_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*C); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_request_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_request_proto_goTypes, + DependencyIndexes: file_request_proto_depIdxs, + MessageInfos: file_request_proto_msgTypes, + }.Build() + File_request_proto = out.File + file_request_proto_rawDesc = nil + file_request_proto_goTypes = nil + file_request_proto_depIdxs = nil +} diff --git a/runtime/tests/request.proto b/runtime/tests/request.proto new file mode 100644 index 0000000..8a27a04 --- /dev/null +++ b/runtime/tests/request.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +option go_package = "./;tests"; + +message A { + string string_value = 1; + int64 int_value = 2; + repeated string string_slice = 3; + B nested_struct = 4; + repeated C struct_slice = 5; +} + +message B { + string string_value = 1 [json_name = "valueString"]; + int64 int_value = 2 [json_name = "valueInt"]; + repeated string string_slice = 3 [json_name = "sliceString"]; +} + +message C { + string string_value = 1; + int64 int_value = 2; +} diff --git a/runtime/request_test.go b/runtime/tests/request_test.go similarity index 71% rename from runtime/request_test.go rename to runtime/tests/request_test.go index 0524aef..37dba87 100644 --- a/runtime/request_test.go +++ b/runtime/tests/request_test.go @@ -1,30 +1,12 @@ -package runtime +package tests import ( "testing" + "github.com/alehechka/grpc-graphql-gateway/runtime" "github.com/stretchr/testify/assert" ) -type A struct { - StringValue string `json:"string_value"` - IntValue int64 `json:"int_value"` - StringSlice []string `json:"string_slice"` - NestedStruct B `json:"nested_struct"` - StructSlice []C `json:"struct_slice"` -} - -type B struct { - StringValue string `json:"string_value"` - IntValue int64 `json:"int_value"` - StringSlice []string `json:"string_slice"` -} - -type C struct { - StringValue string `json:"string_value"` - IntValue int64 `json:"int_value"` -} - func assertStruct(t *testing.T, s *A) { assert.NotNil(t, s) assert.Equal(t, "string", s.StringValue) @@ -70,10 +52,10 @@ func TestMarshalRequest(t *testing.T) { }, }, } - var v *A - err := MarshalRequest(data, &v, false) + var v A + err := runtime.MarshalRequest(data, &v) assert.NoError(t, err) - assertStruct(t, v) + assertStruct(t, &v) } func TestMarshalRequestWithCamelCaseInput(t *testing.T) { @@ -82,9 +64,9 @@ func TestMarshalRequestWithCamelCaseInput(t *testing.T) { "intValue": 1, "stringSlice": []string{"A", "B", "C"}, "nestedStruct": map[string]interface{}{ - "stringValue": "string", - "intValue": 1, - "stringSlice": []string{"A", "B", "C"}, + "valueString": "string", + "valueInt": 1, + "sliceString": []string{"A", "B", "C"}, }, "structSlice": []C{ { @@ -97,8 +79,8 @@ func TestMarshalRequestWithCamelCaseInput(t *testing.T) { }, }, } - var v *A - err := MarshalRequest(data, &v, true) + var v A + err := runtime.MarshalRequest(data, &v) assert.NoError(t, err) - assertStruct(t, v) + assertStruct(t, &v) }