Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@n1ru4l/graphql-live-query
Advanced tools
[![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/
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).
yarn add -E @n1ru4l/graphql-live-query
GraphQLLiveDirective
Add the @live
directive to your schema.
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 ):
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
.
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
.
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".]
FAQs
[![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/
The npm package @n1ru4l/graphql-live-query receives a total of 0 weekly downloads. As such, @n1ru4l/graphql-live-query popularity was classified as not popular.
We found that @n1ru4l/graphql-live-query 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.