Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RPCServer
✓ const { RPCServer } = require('grpc-graphql-server')
✗ const RPCServer = require('grpc-graphql-server')
Named export; default export does not exist.
RPCClient
✓ const { RPCClient } = require('grpc-graphql-server')
✗ const RPCClient = require('grpc-graphql-server').RPCClient
Named export; also accessible via destructuring.
initRPCClient
✓ const { initRPCClient } = require('grpc-graphql-server')
✗ const initRPCClient = require('grpc-graphql-server').initRPCClient
Helper function to initialize RPCClient with config.
Sets up an Express server with a gRPC backend and auto-generated GraphQL schema on /graphql.
const express = require('express');
const { RPCServer } = require('grpc-graphql-server');
const app = express();
class Hello {
SayHello(call, callback) {
const message = 'Hello ' + call.request.name;
if (typeof callback === 'function') {
return callback(null, { message });
}
return Promise.resolve({ message });
}
}
const rpcServer = new RPCServer({
graphql: true,
grpc: {
packages: [{
name: 'helloworld',
services: [{
name: 'Greeter',
implementation: new Hello(),
mutate: false,
}],
}],
},
});
if (rpcServer.gqlServer) {
rpcServer.gqlServer.applyMiddleware({ app });
}
app.listen(3000, () => console.log('Server started on http://localhost:3000'));
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'applyMiddleware')
rpcServer.gqlServer is undefined because graphql: true was not set or server not started.
fixEnsure `graphql: true` is in options and that you check `if (rpcServer.gqlServer)` before calling applyMiddleware.
Error: ENOENT: no such file or directory, open '.../conf/rpc/hello.proto'
Proto file not found in default directory /conf/rpc.
fixSet `protoFile` in options or place the .proto file under `conf/rpc/`.
TypeError: Class constructor cannot be invoked without 'new'
Using RPCServer without `new` keyword.
fixInstantiate with `new RPCServer(options);`
Audit
Dependencies
expressrequiredHTTP server framework required for GraphQL endpoint
@grpc/proto-loaderrequiredLoads .proto files for gRPC service definitions
apollo-server-expressrequiredGraphQL server middleware for Express
@graphql-tools/schemarequiredSchema stitching utilities for GraphQL