Plugin protoc-gen-gql¶
protoc-gen-gql
plugin will generate graphql files with extension .graphqls
rather than go code which means it can be further used for any other language or framework.
The GraphQL objects will only be generated for the gRPC messages of other types that are used in a service either as a input value or a return value (For details check #1)
Install¶
go install github.com/danielvladco/go-proto-gql/protoc-gen-gql@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 graphql file.
- ext
string - Extension of the graphql file, Default: '.graphql' (default "graphql").
Example¶
protoc --gql_out=svc=true:. -I=./api -I=. ./example/codegen/api/pb/*.proto