Registry / devops / grpc-graphql-server

grpc-graphql-server

JSON →
library1.2.1jsnpmunverified

Generates a GraphQL schema from gRPC Protobuf definitions and creates a server. v1.2.1 (latest). Supports both gRPC and GraphQL endpoints from a single service definition. Uses @grpc/proto-loader and apollo-server-express. Allows per-service configuration of mutations vs queries. Requires manual setup of proto file paths and gRPC implementation classes.

npm install grpc-graphql-server
INSTALL
IMPORT
SIG · GRPC-GRAPHQL-SERVE
G
grpc-graphql-server
devopsjavascriptv1.2.1
harness data pending
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'));
Debug
Known issues
gotchaGraphQL endpoint is not enabled by default; must set `graphql: true` in RPCServer options.
fix
Add `graphql: true` to the RPCServer constructor options.
affects: >=1.0.0
gotchaThe `rpcServer.gqlServer` property is undefined if graphql is not enabled or not ready; check before calling applyMiddleware.
fix
Check `if (rpcServer.gqlServer)` before using it.
affects: >=1.0.0
gotchaProto file location defaults to `/conf/rpc` relative to project root; misconfiguration leads to file not found errors.
fix
Set the `protoFile` option explicitly in RPCServer or ensure the proto file is in the expected directory.
affects: >=1.0.0
breakingPackage structure changed from v0.x to v1.x; exports moved from default to named exports.
fix
Use destructured imports: `const { RPCServer } = require('grpc-graphql-server');`
affects: >=1.0.0
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.
fix
Ensure `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.
fix
Set `protoFile` in options or place the .proto file under `conf/rpc/`.
TypeError: Class constructor cannot be invoked without 'new'
Using RPCServer without `new` keyword.
fix
Instantiate with `new RPCServer(options);`
Upgrade
Version history
1.2.1latest on npm
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
Agent activity
6 hits · last 30 days
node
6
Resources
grpc-graphql-server — npm install grpc-graphql-server · libregistry