New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@n1ru4l/graphql-live-query

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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/

  • 0.10.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53K
decreased by-72.36%
Maintainers
1
Weekly downloads
 
Created
Source

@n1ru4l/graphql-live-query

npm version npm downloads

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

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

API

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".]

Keywords

FAQs

Package last updated on 29 Jul 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc