GraphQL Mesh gRPC Handler allows loading gRPC definition files and using reflection, with custom metadata for authorization. Learn more now!
This Handler allows you to load gRPC definition files (.proto).
npm i @omnigraph/grpc
yarn add @omnigraph/grpc
pnpm add @omnigraph/grpc
bun add @omnigraph/grpc
Then you can use it in your Mesh configuration:
mesh.config.ts
import loadGrpcSubgraph from '@omnigraph/grpc'import { defineConfig } from '@graphql-mesh/compose-cli'export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGrpcSubgraph('MyGrpcApi', { // gRPC Endpoint endpoint: 'localhost:50051', // Path to the proto file source: 'grpc/proto/Example.proto', // or source: { file: 'grpc/proto/Example.proto', load: { defaults: true, includeDirs: ['grpc/proto'] } } // Request timeout in milliseconds requestTimeout: 200_000, // Use HTTPS instead HTTP for gRPC connection useHTTPS: false, // Use SSL credentials for gRPC connection credentialsSsl: { rootCA: 'path/to/rootCA.pem', certChain: 'path/to/certChain.pem', }, // Prefix to collect Query method default: list, get prefixQueryMethod: ['list', 'get'], // Select certain fields as Query or Mutation // This overrides `prefixQueryMethod` selectQueryOrMutationField: [ { // You can use a pattern matching with * fieldName: '*RetrieveMovies', type: 'Query', }, // Or you can use a specific field name // This will make the field GetMovie available as a Mutation // Because it would be Query because of `prefixQueryMethod` { fieldName: 'GetMovie', type: 'Mutation' } ] // Headers for the protobuf if URL is provided schemaHeaders: { 'x-api-key': 'my-api-key' } }) } ]})
Use Reflection instead of proto files
If you have configured reflection in your gRPC server, you don’t need to provide source.
When using gRPC reflection (no source), use reflectionMetadata to send metadata only on
reflection requests — for example routing headers required by your infrastructure: