Gathering detailed insights and metrics for @hoangvvo/graphql-jit
Gathering detailed insights and metrics for @hoangvvo/graphql-jit
Gathering detailed insights and metrics for @hoangvvo/graphql-jit
Gathering detailed insights and metrics for @hoangvvo/graphql-jit
npm install @hoangvvo/graphql-jit
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
139 Commits
1 Watching
5 Branches
1 Contributors
Updated on 03 Feb 2022
TypeScript (99.78%)
JavaScript (0.22%)
Cumulative downloads
Total Downloads
Last day
80%
9
Compared to previous day
Last week
-82.4%
12
Compared to previous week
Last month
-30.8%
305
Compared to previous month
Last year
153.2%
8,060
Compared to previous year
5
1
28
This is a fork of zalando-incubator/graphql-jit that features the following improvements:
GraphQL-JS is a very well written runtime implementation of the latest GraphQL spec. However, by compiling to JS, V8 is able to create optimized
code which yields much better performance. graphql-jit
leverages this behaviour of V8 optimization by compiling the queries into functions to significantly improve performance (See benchmarks below)
GraphQL-JS 16 on Node 16.13.0
1$ yarn benchmark skip-json 2Starting introspection 3graphql-js x 1,941 ops/sec ±2.50% (225 runs sampled) 4graphql-jit x 6,158 ops/sec ±2.38% (222 runs sampled) 5Starting fewResolvers 6graphql-js x 26,620 ops/sec ±2.41% (225 runs sampled) 7graphql-jit x 339,223 ops/sec ±2.94% (215 runs sampled) 8Starting manyResolvers 9graphql-js x 16,415 ops/sec ±2.36% (220 runs sampled) 10graphql-jit x 178,331 ops/sec ±2.73% (221 runs sampled) 11Starting nestedArrays 12graphql-js x 127 ops/sec ±1.43% (220 runs sampled) 13graphql-jit x 1,316 ops/sec ±2.58% (219 runs sampled) 14Done in 141.25s.
The goal is to support the June 2018 version of the GraphQL spec.
graphql-js
In order to achieve better performance, the graphql-jit
compiler introduces some limitations.
The primary limitation is that all computed properties must have a resolver and only these can return a Promise
.
1yarn add graphql-jit
For complete working examples, check the examples/ directory
1const typeDefs = ` 2type Query { 3 hello: String 4} 5`; 6const resolvers = { 7 Query: { 8 hello() { 9 return new Promise((resolve) => setTimeout(() => resolve("World!"), 200)); 10 } 11 } 12}; 13 14const { makeExecutableSchema } = require("@graphql-tools/schema"); 15const schema = makeExecutableSchema({ typeDefs, resolvers });
1const query = ` 2{ 3 hello 4} 5`; 6const { parse } = require("graphql"); 7const document = parse(query); 8 9const { compileQuery, isCompiledQuery } = require("graphql-jit"); 10const compiledQuery = compileQuery(schema, document); 11// check if the compilation is successful 12 13if (!isCompiledQuery(compiledQuery)) { 14 console.error(compiledQuery); 15 throw new Error("Error compiling query"); 16}
1const executionResult = await compiledQuery.query(root, context, variables); 2console.log(executionResult);
1const result = await compiledQuery.subscribe(root, context, variables); 2for await (const value of result) { 3 console.log(value); 4}
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 serializerscustomJSONSerializer
{function, default: undefined} - A function to be called with CompilationContext
to produce also a JSON serializer function. The default stringifier function is JSON.stringify
the compiled function that can be called with a root value, a context and the required variables.
(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).
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.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More