Plugin protoc-gen-gogql¶
If you still want to generate go source code instead of graphql then use http://github.com/99designs/gqlgen plugin, and map all the generated go types with all the generated graphql types.
protoc-gen-gogql
plugin generates methods for implementing
github.com/99designs/gqlgen/graphql.Marshaler
and github.com/99designs/gqlgen/graphql.Unmarshaler
interfaces. Now proto enum
s, oneof
s and map
s will work fine with graphql.
This plugin also creates convenience methods that will implement generated by the gqlgen
MutationResolver
and QueryResolver
interfaces.
Install¶
go install github.com/danielvladco/go-proto-gql/protoc-gen-gogql@latest
The protoc compiler expects to find plugins named proto-gen-<PLUGIN_NAME>
on the execution $PATH
.
So first add golang bin directory to the path if it's not already added (also add it to .zshrc
or ~/.bash_profile
depending on the OS you use):
export PATH=${PATH}:$(go env GOPATH)/bin
Usage¶
Run the protoc
command with the arguments for the installed plugin:
Like this:
protoc --gql_out=<ADDITIONAL_ARGUMENTS>:<PATH> -I=./api -I=. ./example/codegen/api/pb/*.proto
Where ADDITIONAL_ARGUMENTS
may be provided in the form of key=value
separated by a comma.
Possible additional arguments:
- svc
bool - Use service annotations for nodes corresponding to a GRPC call.
- merge
bool - Merge all the proto files found in one directory into one file.
Example¶
protoc --gogql_out=paths=source_relative:. -I=./api -I=. ./example/codegen/api/pb/*.proto