graphql-jit

raw JSON →
0.8.7 verified Fri May 01 auth: no javascript

GraphQL JIT Compiler to JavaScript. Current stable version 0.8.7, released monthly. Compiles GraphQL queries into optimized JavaScript functions, offering up to 100x faster execution compared to graphql-js. Key differentiator: ahead-of-time compilation with runtime type validation, supports both ESM and CJS. Requires graphql >=15.

error TypeError: graphqlJit is not a function
cause Attempted to use default import instead of named import.
fix
Replace import graphqlJit from 'graphql-jit' with import { compileQuery } from 'graphql-jit'.
error RangeError: Invalid array length
cause Schema object not passed correctly; often due to mixing graphql versions.
fix
Ensure the same graphql version is used for schema building and compileQuery.
error Cannot find module 'graphql-jit' or its corresponding type declarations.
cause Missing peer dependency graphql or wrong module resolution.
fix
Install both: npm install graphql-jit graphql.
breaking Node.js 12 support dropped in v0.8.0
fix Use Node.js 14+ (recommended 18+).
breaking Switched to ESM-only in v0.8.5, breaking CommonJS require()
fix Use import syntax or upgrade to Node 18+ with 'type': 'module' in package.json.
gotcha compileQuery returns an object that may have 'query' or 'subscribe' properties, but also may throw a custom error if there is a validation issue. Not always a direct function.
fix Check if 'query' key exists on the result before calling as function.
deprecated The option 'useExperimentalPathBasedSkipInclude' is experimental and may be removed.
fix Migrate to the new default logic when the option is removed in future releases.
gotcha Non-null field returning null can cause TypeError in v0.8.5 with certain schemas.
fix Upgrade to v0.8.6+ which fixes this issue.
gotcha Default import (import graphqlJit from 'graphql-jit') does not exist; you must use named imports.
fix Use import { compileQuery } from 'graphql-jit'.
npm install graphql-jit
yarn add graphql-jit
pnpm add graphql-jit

Compile a simple GraphQL query and execute it. Shows schema building, parsing, validation, compilation, and execution.

import { compileQuery } from 'graphql-jit';
import { validate, parse, buildSchema, GraphQLError } from 'graphql';

const schema = buildSchema(`
  type Query { hello: String }
`);
const requestString = '{ hello }';
const document = parse(requestString);
const errors = validate(schema, document);
if (errors.length > 0) throw new Error(errors.map(e => e.message).join(', '));

const compiledQuery = compileQuery(schema, document);
if ('query' in compiledQuery) {
  const result = compiledQuery.query(null, {}, {}, {});
  console.log(result);
}