Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hoangvvo/graphql-jit

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hoangvvo/graphql-jit

GraphQL JIT Compiler to JS

  • 0.6.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

GraphQL JIT

Build codecov

This is a fork of zalando-incubator/graphql-jit that features the following improvements:

  • Support for GraphQL Subscription
  • Custom JSON Stringify factory function
  • Minimal dependencies for lightweight bundle

If you do not have the above use cases, it is better to stick with the original repo. Check out the their README to learn more about graphql-jit.

Install

yarn add @hoangvvo/graphql-jit
// or
npm i @hoangvvo/graphql-jit

Usage

import { compileQuery, isCompiledQuery } from "graphql-jit";

const query = `{ hello }`;

const document = parse(query);

const compiledQuery = compileQuery(schema, document);

if (!isCompiledQuery(compiledQuery)) {
  console.error(compiledQuery);
  throw new Error("Error compiling query");
}

#### Execute the Query

```js
const executionResult = await compiledQuery.query(root, context, variables);
console.log(executionResult);
Subscribe to the Query
const result = await compiledQuery.subscribe(root, context, variables);
for await (const value of result) {
  console.log(value);
}

API

compiledQuery = compileQuery(schema, document, operationName, compilerOptions)

Compiles the document AST, using an optional operationName and compiler options.

  • schema {GraphQLSchema} - graphql schema object

  • document {DocumentNode} - document query AST ,can be obtained by parse from graphql

  • operationName {string} - optional operation name in case the document contains multiple operations(queries/mutations/subscription).

  • compilerOptions {Object} - Configurable options for the compiler

    • disableLeafSerialization {boolean, default: false} - disables leaf node serializers. The serializers validate the content of the field at runtime so this option should only be set to true if there are strong assurances that the values are valid.
    • customSerializers {Object as Map, default: {}} - Replace serializer functions for specific types. Can be used as a safer alternative for overly expensive serializers
    • customJSONSerializer {function, default: undefined} - A function to be called with CompilationContext to produce also a JSON serializer function. The default stringifier function is JSON.stringify
compiledQuery.query(root: any, context: any, variables: Maybe<{ [key: string]: any }>)

the compiled function that can be called with a root value, a context and the required variables.

compiledQuery.subscribe(root: any, context: any, variables: Maybe<{ [key: string]: any }>)

(available for GraphQL Subscription only) the compiled function that can be called with a root value, a context and the required variables to produce either an AsyncIterator (if successful) or an ExecutionResult (error).

compiledQuery.stringify(value: any)

the compiled function for producing a JSON string. It will be JSON.stringify unless compilerOptions.customJSONSerializer is a function. The value argument should be the return of the compiled GraphQL function.

LICENSE

MIT

Keywords

FAQs

Package last updated on 21 Sep 2021

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