# @n1ru4l/graphql-live-query

> [![npm version](https://img.shields.io/npm/v/@n1ru4l/graphql-live-query.svg)](https://www.npmjs.com/package/@n1ru4l/graphql-live-query) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/graphql-live-query.svg)](https://www.npmjs.com/package/@n1ru4l/

Latest version **0.11.0** (published 2026-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @n1ru4l/graphql-live-query
pnpm add @n1ru4l/graphql-live-query
yarn add @n1ru4l/graphql-live-query
bun add @n1ru4l/graphql-live-query
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.11.0 |
| Published | 2026-07-20 |
| First published | 2020-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 441 |
| Author | n1ru4l |
| Maintainers | n1ru4l |
| Keywords | graphql, query, live, real-time |

## Links

- npm: https://www.npmjs.com/package/@n1ru4l/graphql-live-query
- Repository: https://github.com/n1ru4l/graphql-live-query
- Homepage: https://github.com/n1ru4l/graphql-live-queries#readme
- Issues: https://github.com/n1ru4l/graphql-live-query/issues
- npm.io page: https://npm.io/package/@n1ru4l/graphql-live-query

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.11.0 (latest) — 2026-07-20
- 0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda (rc) — 2026-07-20
- 0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe (alpha) — 2026-07-20
- 0.11.0-alpha-20260720124524-d45653cebd08165a479f0429361ce3c16fd78c9b — 2026-07-20
- 0.11.0-alpha-20260720124511-240b6a46c363f4bbafde68ae0e9e891c3f6bbb5d — 2026-07-20
- 0.11.0-alpha-20260720124457-928327edc3c222db4eb01fccf303ab9eb4371973 — 2026-07-20
- 0.11.0-alpha-20260720124441-82de291d864718098034d09cd01b08d6af3e6775 — 2026-07-20
- 0.11.0-alpha-20260720124404-7f174629b0bcf2de3b7fbb5f6b17396bc569dbea — 2026-07-20
- 0.11.0-alpha-20260720124401-2a62f4d87d544f341cfbd91655d9d84a69f3696b — 2026-07-20
- 0.11.0-alpha-20260720124348-3b89a8392c5cfa595c4e9324aa1c3f95941e0bad — 2026-07-20
- 0.11.0-alpha-20260720124331-94085ecd5b7282816c848800dfaaccdf8e252c03 — 2026-07-20
- 0.11.0-alpha-20260720123954-9ecba3d81dc0d1e580ed18406d930eb5c1820b45 — 2026-07-20
- 0.11.0-alpha-4a0d9f8.0 — 2022-08-10
- 0.10.1-alpha-20220809152435-afca7b0 — 2022-08-09
- 0.11.0-alpha-4f39e4d.0 — 2022-08-08
- … 24 more at https://npm.io/package/@n1ru4l/graphql-live-query/versions

## README

# @n1ru4l/graphql-live-query

[![npm version](https://img.shields.io/npm/v/@n1ru4l/graphql-live-query.svg)](https://www.npmjs.com/package/@n1ru4l/graphql-live-query) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/graphql-live-query.svg)](https://www.npmjs.com/package/@n1ru4l/graphql-live-query)

Primitives for adding GraphQL live query operation support to any GraphQL server.

For a usage of those utility functions check out `InMemoryLiveQueryStore`(https://github.com/n1ru4l/graphql-live-queries/tree/main/packages/in-memory-live-query-store/src/InMemoryLiveQueryStore.ts).

## Install Instructions

```bash
yarn add -E @n1ru4l/graphql-live-query
```

## API

### `GraphQLLiveDirective`

Add the `@live` directive to your schema.

```ts
import { GraphQLSchema, specifiedDirectives } from "graphql";
import { GraphQLLiveDirective } from "@n1ru4l/graphql-live-query";
import { query, mutation, subscription } from "./schema";

const schema = new GraphQLSchema({
  query,
  mutation,
  subscription,
  directives: [
    GraphQLLiveDirective,
    /* Keep @defer/@stream/@if/@skip */ ...specifiedDirectives,
  ],
});
```

**Note:** If you are using a SDL first approach for defining your schema (such as advocated by `makeExecutableSchema`) you must add the directly to your type-definitions. In order to be as up to date as possible we recommend using `graphql-tools/utils` `astFromDirective` together with `print` exported from `graphql` for generating the SDL from `GraphQLLiveDirective`.

**Example ([on CodeSandbox](https://codesandbox.io/s/graphqllivedirective-usage-with-makeexecutableschema-xv2q5?file=/src/schema.ts:376-483)
):**

```ts
import { makeExecutableSchema } from "@graphql-tools/schema";
import { astFromDirective } from "@graphql-tools/utils";
import { GraphQLLiveDirective } from "@n1ru4l/graphql-live-query";
import { print, GraphQLSchema } from "graphql";

const typeDefinitions = /* GraphQL */ `
  type Query {
    ping: Boolean
  }
`;

const resolvers = {
  Query: {
    ping: () => true
  }
};

const liveDirectiveTypeDefs = print(
  astFromDirective(GraphQLLiveDirective)
);

export const schema = makeExecutableSchema({
  typeDefs: [typeDefinitions, liveDirectiveTypeDefs],
  resolvers
});
```

### `isLiveQueryOperationDefinitionNode`

Determine whether a `DefinitionNode` is a `LiveQueryOperationDefinitionNode`.

```ts
import { parse, getOperationAST } from "graphql";
import { isLiveQueryOperationDefinitionNode } from "@n1ru4l/graphql-live-query";

const liveQueryOperationDefinitionNode = getOperationAST(
  parse(/* GraphQL */ `
    query @live {
      me {
        id
        login
      }
    }
  `)
);

isLiveQueryOperationDefinitionNode(liveQueryOperationDefinitionNode); // true

const queryOperationDefinitionNode = getOperationAST(
  parse(/* GraphQL */ `
    query {
      me {
        id
        login
      }
    }
  `)
);

isLiveQueryOperationDefinitionNode(queryOperationDefinitionNode); // false

const conditionalLiveQueryDefinitionNode = getOperationAST(
  parse(/* GraphQL */ `
    query($isClient: Boolean = false) @live(if: $isClient) {
      me {
        id
        login
      }
    }
  `)
);

isLiveQueryOperationDefinitionNode(conditionalLiveQueryDefinitionNode); // false
isLiveQueryOperationDefinitionNode(
  conditionalLiveQueryDefinitionNode,
  /* variables */ {
    isClient: false,
  }
); // false
isLiveQueryOperationDefinitionNode(
  conditionalLiveQueryDefinitionNode,
  /* variables */ {
    isClient: true,
  }
); // true
```

### `NoLiveMixedWithDeferStreamRule`

Validation rule for raising a GraphQLError for a operation that use `@live` mixed with `@defer` and `@stream`.

```ts
import { parse, validate, specifiedRules } from "graphql";
import { NoLiveMixedWithDeferStreamRule } from "@n1ru4l/graphql-live-query";
import schema from "./schema";

const document = parse(/* GraphQL */ `
  query @live {
    users @stream {
      id
      login
    }
  }
`);

const [error] = validate(schema, document, [
  /* default validation rules */ ...specifiedRules,
  NoLiveMixedWithDeferStreamRule,
]);

console.log(error); // [GraphQLError: Cannot mix "@stream" with "@live".]
```

---
_Source: https://npm.io/package/@n1ru4l/graphql-live-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
