
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
@envelop/live-query
Advanced tools
@envelop/live-queryThe easiest way of adding live queries to your GraphQL server!
Push new data to your clients automatically once the data selected by a GraphQL operation becomes
stale by annotating your query operation with the @live directive.
query UserProfile @live {
me {
id
login
bio
}
}
The invalidation mechanism is based on GraphQL ID fields and schema coordinates. Once a query operation has been invalidated, the query is re-executed and the result is pushed to the client.
yarn add @envelop/live-query @n1ru4l/in-memory-live-query-store
makeExecutableSchema from graphql-toolsimport { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine, useExtendContext, useSchema } from '@envelop/core'
import { useLiveQuery } from '@envelop/live-query'
import { makeExecutableSchema } from '@graphql-tools/schema'
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'
const schema = makeExecutableSchema({
typeDefs: [
/* GraphQL */ `
type Query {
greetings: [String!]
}
`,
GraphQLLiveDirectiveSDL
],
resolvers: {
Query: {
greetings: (_, __, context) => context.greetings
}
}
})
const liveQueryStore = new InMemoryLiveQueryStore()
const greetings = ['Hello', 'Hi', 'Ay', 'Sup']
// Shuffle greetings and invalidate queries selecting Query.greetings every second.
setInterval(() => {
const firstElement = greetings.pop()
greetings.unshift(firstElement)
liveQueryStore.invalidate('Query.greetings')
}, 1000)
const getEnveloped = envelop({
plugins: [
useEngine({ parse, validate, specifiedRules, execute, subscribe }),
useSchema(schema),
useLiveQuery({ liveQueryStore }),
useExtendContext(() => ({ greetings }))
/* other plugins */
]
})
GraphQLSchema from graphqlYou need to pass the GraphQLLiveDirective to the list of directives:
import { GraphQLSchema } from 'graphql'
import { GraphQLLiveDirective } from '@envelop/live-query'
const schema = new GraphQLSchema({
directives: [...specifiedDirectives, GraphQLLiveDirective]
})
By using a patch middleware you can significantly reduce the size of the GraphQL execution result
payload that is sent over the wire from the server to the client. We recommend using the
@n1ru4l/graphql-live-query-patch-jsondiffpatch patch generator.
You can learn more about it here.
yarn add @n1ru4l/graphql-live-query-patch-jsondiffpatch
import { applyLiveQueryJSONDiffPatchGenerator } from '@n1ru4l/graphql-live-query-patch-jsondiffpatch'
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'
const liveQueryStore = new InMemoryLiveQueryStore()
const plugin = useLiveQuery({
liveQueryStore,
applyLiveQueryPatchGenerator: applyLiveQueryJSONDiffPatchGenerator
})
This plugin requires you to use a graphql transports that supports usage of the @defer and
@stream directives, as it is built upon the same concepts (return an AsyncIterable from
execute).
The following transports have been successfully tested:
| Package | Transport | Version | Downloads |
|---|---|---|---|
@n1ru4l/socket-io-graphql-server | GraphQL over Socket.io (WebSocket/HTTP Long Polling) | ||
graphql-helix | GraphQL over HTTP (IncrementalDelivery/SSE) | ||
graphql-ws | GraphQL over WebSocket (WebSocket) | ||
graphql-sse | GraphQL over Server-Sent Events (SSE) |
For more details check out the live query repository or the introduction blog post.
FAQs
The easiest way of adding live queries to your GraphQL server!
We found that @envelop/live-query demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.