Gateway (PoC)¶
At this point we have a PoC gateway that will translate the messages on the fly.
The gateway can be configured in two modes:
pointing to a list of grpc endpoints (grpc reflection must be enabled on the grpc servers).
The gateway will query the servers for protobuf descriptors and generate a graphql schema abstract tree.
The requests to the gateway will be transformed on the fly to grpc servers without any additional code generation
or writing any code at all. See examples/gateway
for usage more info.
Config the gateway¶
To configure the gateway create a config.yaml
file and provide it to our gateway executable via --config
flag.
For example: ./gateway --config config.yaml
Gateway config options:
# Generate documentation from the comments left in proto files
docs: true
# Cors configuration for more details check https://github.com/rs/cors/blob/master/cors.go#L32
cors: { }
# The address to serve the gateway on (Default :8080)
address: ":8080"
# Start the gateway with TLS
tls:
# Path to the TLS certificate
certificate: ""
# Path to the TLS private key
private_key: ""
# gRPC config options (It is made as a separate category because in the future we can add other protocols too,
# such as: OpenAPI, OpenRPC, GraphQL, etc.
grpc:
# Import paths provided to the proto parser it is similar to `-I` or `--proto_path` flag on `protoc` cli tool.
# It is required if your services import proto files.
import_paths:
- ./api
services:
# The gRPC server address
- address: "localhost:8081"
# Authentication options to connect to the gRPC server if needed, otherwise will use insecure connection.
authentication:
# Authenticate using TLC
tls:
# Path to the TLS certificate
certificate: ""
# Path to the TLS private key
private_key: ""
# Enable automatic discovery if the gRPC server has enabled reflection.
# Cannot be used together with `proto_files` option.
reflection: true
# The entry proto file where the gRPC services are defined.
# If your proto files have any dependencies they should be present in one of the specified `import_paths`
proto_files:
- ./grpc_service.proto
Docker image¶
A docker image with the gateway is also available with the latest tags:
To run the gateway using docker run:
docker run ghcr.io/danielvladco/go-proto-gql/gateway
Example¶
In this example we will spin up two gRPC servers and a gateway server that points to them.
To run the demo example follow the next steps:
- Go to
./example/gateway/
- Run
docker-compose up
- Navigate to
http://localhost:8080/playground
in your browser - Have fun sending requests to the gRPC servers directly from your browser!
Supported features¶
- Run with TLS certificates
- Cors
- GRPC authentication
- TLS authentication
- GRPC other authentication methods (more research required)
- GRPC reflection
- Proto files parsing
- Adapt gRPC to GraphQL
- GRPC call to Mutation
- GRPC call to Query
- GRPC stream to Subscription
- Proto messages to GraphQL types
- Proto messages to GraphQL inputs
- Proto enums to GraphQL enums
- Proto maps to GraphQL array of types for map entries
- Proto maps to GraphQL array of inputs for map entries
- Proto oneofs to GraphQL unions
- Proto oneofs to GraphQL directive attached to the fields that must be unique
- Adapt OpenAPI to GraphQL #45
- Adapt OpenRPC to GraphQL #46
- Proxy GraphQL to GraphQL #47