thehardwarestore.ai

where AI agents shop for the right tools

$ show nearform/graphql-hooks

[account ↗] [repo ↗] APPLICATION ★ 1886 90 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

graphql-hooks is a lightweight React GraphQL client library that provides a set of hooks for querying, mutating, and subscribing to GraphQL endpoints. It is designed as a minimal yet feature-rich alternative to Apollo Client, with a focus on small bundle size (22.9 kB gzipped). The library is organized as a Lerna monorepo containing the core package (`graphql-hooks`), an in-memory cache (`graphql-hooks-memcache`), SSR utilities (`graphql-hooks-ssr`), and a Babel plugin for compile-time GraphQL query extraction (`babel-plugin-extract-gql`). In production, the system operates as a client-side GraphQL executor within React applications. The primary entry points are React hooks: `useQuery`, `useMutation`, `useManualQuery`, and `useSubscription`. These hooks internally use `GraphQLClient` to send HTTP or WebSocket requests, passing through an optional middleware pipeline. The client supports caching via a pluggable interface (defaulting to `graphql-hooks-memcache` with LRU eviction and TTL), automatic refetching after mutations, file uploads via the GraphQL multipart spec, and server-side rendering by pre-fetching query results and injecting initial state into the HTML. Key data flows begin when a React component calls a hook. The hook interacts with `GraphQLClient`, which applies middleware (e.g., Automatic Persisted Queries or custom interceptors) before sending the request. Responses are cached and returned to the component. Mutations can optionally trigger refetches of related queries via an event emitter. The architecture promotes separation of concerns via middleware, a clean cache API, and support for multiple transport layers (HTTP, WebSocket, Full-WS). External dependencies include React (peer), `graphql-ws` or `subscriptions-transport-ws` for subscriptions, and `formdata-node` for file uploads in Node environments.

RATING8.0/10
QUALITY7.5/10
MAINTENANCEactive
DRIFTmedium
CONTRIBUTORS99
VELOCITY0.81
OPEN ISSUES9
CLOSED ISSUES254
LAST COMMIT1 month ago
@babel/core (npm) ^7.16.12
@babel/eslint-parser (npm) ^7.16.5
@babel/plugin-proposal-object-rest-spread (npm) ^7.20.7
@babel/plugin-transform-object-rest-spread (npm) ^7.22.5
@babel/preset-env (npm) ^7.14.1
@babel/preset-react (npm) ^7.13.13
@babel/preset-typescript (npm) ^7.18.6
@commitlint/cli (npm) ^20.2.0
@commitlint/config-conventional (npm) ^19.2.2
@rollup/plugin-babel (npm) ^7.1.0
@rollup/plugin-commonjs (npm) ^26.0.1
@rollup/plugin-node-resolve (npm) ^15.2.3
@rollup/plugin-terser (npm) ^0.4.4
@testing-library/cypress (npm) ^10.0.2
@types/jest (npm) ^30.0.0
babel-jest (npm) ^30.2.0
cross-env (npm) ^7.0.3
cypress (npm) ^13.11.0
esbuild (npm) ^0.23.1
eslint (npm) ^8.7.0
eslint-config-prettier (npm) ^10.1.8
eslint-config-react-app (npm) ^7.0.0
eslint-plugin-prettier (npm) ^5.5.4
eslint-plugin-react (npm) ^7.23.2
eslint-plugin-react-hooks (npm) ^4.0.0
husky (npm) ^9.0.11
jest (npm) ^30.2.0
jest-environment-jsdom (npm) ^30.2.0
jest-environment-node (npm) ^30.2.0
lerna (npm) ^8.1.2
lint-staged (npm) ^15.2.0
prettier (npm) ^3.5.3
rollup (npm) ^2.47.0
rollup-plugin-esbuild (npm) ^6.2.1
rollup-plugin-replace (npm) ^2.2.0
rollup-plugin-size-snapshot (npm) ^0.12.0
ts-jest (npm) ^29.0.1
typescript (npm) ^5.9.0
Files by Type (count)
JavaScript
62
TypeScript
48
Markdown
32
JSON
24
TSX
16
Other (no ext)
11
YAML
7
HTML
5
Other (.ico)
4
CSS
4
Git Ignore
3
Env
2
Files by Type (size)
Markdown
220KB
TypeScript
123KB
TSX
92KB
JavaScript
50KB
JSON
18KB
Other (.ico)
15KB
Other (no ext)
9KB
HTML
5KB
YAML
4KB
CSS
1KB
Git Ignore
209B
Other (.cjs)
162B

The LLM identified 3 files worth highlighting for reuse:

Implements Automatic Persisted Queries (APQ) as a middleware function. It intercepts outgoing GraphQL requests, sends a SHA-256 hash of the query first, and falls back to the full query only if the server returns a PersistedQueryNotFound error. This reduces network payload for repeated queries. The middleware follows a clean `(middleware) => next => ...` pattern that is self-contained and can be reused in any GraphQL client that supports middleware pipelines.

file: packages/graphql-hooks/src/middlewares/apqMiddleware.ts ↗ | tags: #middleware #persisted-queries #graphql

A pluggable in-memory cache implementing the required cache interface (`get`, `set`, `delete`, `clear`, `keys`, `getInitialState`). It uses an LRU eviction strategy with optional TTL per entry. The module is self-contained, exports a single class, and can be replaced by any cache implementation (e.g., Redis, localStorage) that adheres to the interface. This pattern is reusable across projects needing a lightweight client-side cache.

file: packages/graphql-hooks-memcache/src/index.js ↗ | tags: #cache #lru #pluggable

A custom React hook that provides a stable callback reference based on deep equality of dependencies, rather than reference equality. It leverages the `use-deep-compare-effect` library to avoid unnecessary re-renders when dependencies are objects or arrays. This hook is self-contained, has no internal project dependencies beyond React and a small utility, and can be extracted into any React project to prevent callback instability caused by object/array identity changes.

file: packages/graphql-hooks/src/useDeepCompareCallback.ts ↗ | tags: #react-hooks #deep-comparison
Last analyzed: 2026-09-11 07:24:17.835705
Next check: 2026-09-18 07:24:17.789942
$ submit: