gRPC / Protobuf
This Handler allows you to load gRPC definition files (.proto
).
npm i @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'],
// 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
.
mesh.config.ts
import { defineConfig } from '@graphql-mesh/compose-cli'
import loadGrpcSubgraph from '@omnigraph/grpc'
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadGrpcSubgraph('MyGrpcApi', {
endpoint: 'localhost:50051'
})
}
]
})
Custom Metadata for Authorization
Here you can use metaData
field to pass some custom metadata from the context.
mesh.config.ts
import { defineConfig } from '@graphql-mesh/compose-cli'
import loadGrpcSubgraph from '@omnigraph/grpc'
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadGrpcSubgraph('MyGrpcApi', {
endpoint: 'localhost:50051',
metaData: {
authorization: "Bearer {context.headers['x-my-token']}",
someStaticValue: 'MyStaticValue'
}
})
}
]
})