Registry / devops / rtk-query-grpc

rtk-query-grpc

JSON →
library1.0.0jsnpmunverified

A library that wraps RTK Query to simplify integration with gRPC APIs while preserving TypeScript type safety. Version 1.0.0 is the initial release with a work-in-progress API. It provides a createGrpcDefinition helper that takes a gRPC client and options, and returns a configuration compatible with createApi from @reduxjs/toolkit. Endpoints use builder.query and builder.mutation with string method names and query functions that map gRPC message objects (AsObject) to actual request objects. Key differentiators: eliminates manual serialization, provides type-safe gRPC integration directly within RTK Query's caching and hooks model.

npm install rtk-query-grpc
INSTALL
IMPORT
SIG · RTK-QUERY-GRPC
R
rtk-query-grpc
devopsjavascriptv1.0.0
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.

createGrpcDefinition
✓ import { createGrpcDefinition } from 'rtk-query-grpc'
✗ const createGrpcDefinition = require('rtk-query-grpc')
ESM-only; CommonJS require is not supported.
createApi
✓ import { createApi } from '@reduxjs/toolkit/query/react'
✗ import { createApi } from '@reduxjs/toolkit'
createApi is exported from the React-specific RTK Query endpoint, not from the core @reduxjs/toolkit.
useListUploadsQuery hook
✓ const { useListUploadsQuery } = uploadAPI; // from the returned API object
✗ import { useListUploadsQuery } from 'rtk-query-grpc'
Hooks are auto-generated on the API object returned by createApi, not exported from the package.

Shows how to define a gRPC API using createGrpcDefinition with RTK Query endpoints, including query and mutation definitions.

import { createGrpcDefinition } from 'rtk-query-grpc'; import { createApi } from '@reduxjs/toolkit/query/react'; import { UploadServicePromiseClient } from './proto/upload_grpc_pb'; import { ListUploadsRequest, GetUploadRequest, CreateUploadRequest, DeleteUploadRequest, Upload } from './proto/upload_pb'; export const uploadAPI = createApi(createGrpcDefinition({ client: UploadServicePromiseClient, clientArgs: ['http://localhost:8081'], reducerPath: 'api', entityTypes: ['Upload'], endpoints: (builder) => ({ listUploads: builder.query('listUploads', { query: (r: ListUploadsRequest.AsObject) => new ListUploadsRequest() .setParent(r.parent) .setPageSize(r.pageSize) .setPageToken(r.pageToken), provides: ({ uploadsList }) => [ ...uploadsList.map(({ name }) => builder.result('Upload', name)), builder.result('Upload', 'LIST'), ], }), getUpload: builder.query('getUpload', { query: (r: GetUploadRequest.AsObject) => new GetUploadRequest().setName(r.name), provides: (_, r) => [builder.result('Upload', r.name)], }), createUpload: builder.mutation('createUpload', { query: (r: CreateUploadRequest.AsObject) => new CreateUploadRequest().setParent(r.parent).setUpload(new Upload()), invalidates: [builder.result('Upload', 'LIST')], }), deleteUpload: builder.mutation('deleteUpload', { query: (r: DeleteUploadRequest.AsObject) => new DeleteUploadRequest().setName(r.name), invalidates: (_, { name }) => [builder.result('Upload', name)], }), }), }));
Debug
Known issues
breakingcreateGrpcDefinition API is work-in-progress and may change without notice.
fix
Pin version and monitor releases for breaking changes.
affects: 1.0.0
deprecatedThe package uses @rtk-incubator/rtk-query which is deprecated in favor of @reduxjs/toolkit's built-in RTK Query.
fix
Use @reduxjs/toolkit (>=1.6.0) that includes RTK Query natively. Update peerDependencies accordingly.
affects: >=0.2.0
gotchaclientArgs expects an array of arguments to the client constructor; typically a single string URL.
fix
Ensure clientArgs is an array, even for a single argument, e.g., ['http://localhost:8081'].
affects: 1.0.0
Errors
Common errors & fixes
TypeError: client is not a constructor
The client class passed to createGrpcDefinition is not a constructor or is wrong type.
fix
Ensure you pass a gRPC client class (e.g., MyServicePromiseClient) not an instance.
Cannot find module '@rtk-incubator/rtk-query'
The peer dependency @rtk-incubator/rtk-query is not installed.
fix
Run npm install @rtk-incubator/rtk-query@>=0.2.0, or use @reduxjs/toolkit >=1.6.0 which includes RTK Query.
Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
Attempting to use require() instead of ESM import.
fix
Use ES module imports (import ... from 'rtk-query-grpc').
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@reduxjs/toolkitrequiredPeer dependency; required for createApi and core RTK Query functionality
@rtk-incubator/rtk-queryrequiredPeer dependency; required for RTK Query types and utilities
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
rtk-query-grpc — npm install rtk-query-grpc · libregistry