@grpc Directive

The @grpc directive resolves a field by invoking a gRPC service method. It requires a linked protobuf definition via the @link directive.

Fields

FieldTypeDefaultDescription
urlStringRequiredThe gRPC server address (e.g. https://grpc-server:50051).
methodStringRequiredFully qualified gRPC method name (e.g. news.NewsService.GetNews).
bodyStringnullTemplate for the gRPC request message body.
headers[Header][]Additional metadata headers sent with the gRPC call.
batch_key[String][]Field path used for request batching.
dedupeBooleanfalseDeduplicate identical in-flight gRPC calls.
selectStringnullPath selector to extract a subset of the response message.
on_response_bodyStringnullJS function name to transform the response.

Example

schema @link(id: "news", src: "./news.proto", type_of: Protobuf) @server(port: 8000) {
  query: Query
}

type Query {
  news: [NewsEntry]
  @grpc(
    url: "https://grpc-server:50051"
    method: "news.NewsService.ListNews"
  )
  newsById(id: Int!): NewsEntry
  @grpc(
    url: "https://grpc-server:50051"
    method: "news.NewsService.GetNews"
    body: { id: "{{.args.id}}" }
  )
}

type NewsEntry {
  id: Int!
  title: String!
  content: String!
}

The method field must match the package, service, and RPC name defined in the .proto file.