
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
@n1ru4l/in-memory-live-query-store
Advanced tools
[](https://www.npmjs.com/package/@n1ru4l/in-memory-live-query-store) [](https://www.np
A GraphQL live query store that tracks, invalidates and re-executes registered operations. Drop in replacement for graphql-js
execute
. Add live query capabilities to your existing GraphQL schema.
Check out the todo example server for a sample integration.
yarn add -E @n1ru4l/in-memory-live-query-store
InMemoryLiveQueryStore
A InMemoryLiveQueryStore
instance tracks, invalidates and re-executes registered live query operations.
The store will keep track of all root query field coordinates (e.g. Query.todos
) and global resource identifiers (e.g. Todo:1
). The store can than be notified to re-execute live query operations that select a given root query field or resource identifier by calling the invalidate
method with the corresponding values.
A resource identifier is composed out of the typename and the actual resolved id value separated by a colon, but can be customized. For ensuring that the store keeps track of all your query resources you should always select the id
field on your object types. The store will only keep track of fields with the name id
and the type ID!
(GraphQLNonNull(GraphQLID)
).
import { InMemoryLiveQueryStore } from "@n1ru4l/in-memory-live-query-store";
import { parse, execute as executeImplementation } from "graphql";
import { schema } from "./schema";
const inMemoryLiveQueryStore = new InMemoryLiveQueryStore();
const rootValue = {
todos: [
{
id: "1",
content: "Foo",
isComplete: false,
},
],
};
const execute = inMemoryLiveQueryStore.makeExecute(executeImplementation);
execute({
schema, // make sure your schema has the GraphQLLiveDirective from @n1ru4l/graphql-live-query
operationDocument: parse(/* GraphQL */ `
query todosQuery @live {
todos {
id
content
isComplete
}
}
`),
rootValue: rootValue,
contextValue: {},
variableValues: null,
operationName: "todosQuery",
}).then(async (result) => {
if (isAsyncIterable(result)) {
for (const value of result) {
console.log(value);
}
}
});
// Invalidate by resource identifier
rootValue.todos[0].isComplete = true;
inMemoryLiveQueryStore.invalidate(`Todo:1`);
// Invalidate by root query field coordinate
rootValue.todos.push({ id: "2", content: "Baz", isComplete: false });
inMemoryLiveQueryStore.invalidate(`Query.todos`);
The execute
function returned from InMemoryLiveQueryStore.makeExecute
is a drop-in replacement for the default execute
function exported from graphql-js
. You can provide your own execute
function from any graphql-js version or other library.
Pass it to your favorite graphql transport that supports returning AsyncIterableIterator
(or AsyncGenerator
) from execute
and thus delivering incremental query execution results.
List of known and tested compatible transports/servers:
Package | Transport | Version | Downloads |
---|---|---|---|
@n1ru4l/socket-io-graphql-server | WebSocket/HTTP Long Polling | ||
graphql-helix | HTTP/SSE | ||
graphql-ws | WebSocket |
You can use Redis to synchronize invalidations across multiple instances.
import Redis from "ioredis";
import {
InMemoryLiveQueryStore,
InMemoryLiveQueryStoreParameter,
} from "@n1ru4l/in-memory-live-query-store";
import { ExecutionArgs, execute as defaultExecute } from "graphql";
const CHANNEL = "LIVE_QUERY_INVALIDATIONS";
export class RedisLiveQueryStore {
pub: Redis.Redis;
sub: Redis.Redis;
liveQueryStore: InMemoryLiveQueryStore;
constructor(redisUrl: string, parameter?: InMemoryLiveQueryStoreParameter) {
this.pub = new Redis(redisUrl);
this.sub = new Redis(redisUrl);
this.liveQueryStore = new InMemoryLiveQueryStore(parameter);
this.sub.subscribe(CHANNEL, (err) => {
if (err) throw err;
});
this.sub.on("message", (channel, resourceIdentifier) => {
if (channel === CHANNEL && resourceIdentifier)
this.liveQueryStore.invalidate(resourceIdentifier);
});
}
async invalidate(identifiers: Array<string> | string) {
if (typeof identifiers === "string") {
identifiers = [identifiers];
}
for (const identifier of identifiers) {
this.pub.publish(CHANNEL, identifier);
}
}
makeExecute(execute: typeof defaultExecute) {
return this.liveQueryStore.makeExecute(args);
}
}
FAQs
[](https://www.npmjs.com/package/@n1ru4l/in-memory-live-query-store) [](https://www.np
The npm package @n1ru4l/in-memory-live-query-store receives a total of 4,721 weekly downloads. As such, @n1ru4l/in-memory-live-query-store popularity was classified as popular.
We found that @n1ru4l/in-memory-live-query-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.