graphql-jit
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -1,2 +0,2 @@ | ||
import { DocumentNode, GraphQLError, GraphQLFormattedError, GraphQLObjectType, GraphQLOutputType, GraphQLSchema } from "graphql"; | ||
import { DocumentNode, GraphQLError, GraphQLFormattedError, GraphQLObjectType, GraphQLOutputType, GraphQLScalarSerializer, GraphQLSchema } from "graphql"; | ||
import { ExecutionContext } from "graphql/execution/execute"; | ||
@@ -22,2 +22,5 @@ import { FieldNode } from "graphql/language/ast"; | ||
disableLeafSerialization: boolean; | ||
customSerializers: { | ||
[key: string]: (v: any) => any; | ||
}; | ||
} | ||
@@ -57,3 +60,3 @@ /** | ||
query: (root: any, context: any, variables: Maybe<{ | ||
[key: string]: any; | ||
[key: string]: GraphQLScalarSerializer<any>; | ||
}>) => Promise<ExecutionResult> | ExecutionResult; | ||
@@ -60,0 +63,0 @@ stringify: (v: any) => string; |
@@ -38,3 +38,3 @@ "use strict"; | ||
try { | ||
const options = Object.assign({ customJSONSerializer: false, disableLeafSerialization: false }, partialOptions); | ||
const options = Object.assign({ customJSONSerializer: false, disableLeafSerialization: false, customSerializers: {} }, partialOptions); | ||
// If a valid context cannot be created due to incorrect arguments, | ||
@@ -268,3 +268,3 @@ // a "Response" with only errors is returned. | ||
else { | ||
context.dependencies.set(getSerializerName(type.name), getSerializer(type)); | ||
context.dependencies.set(getSerializerName(type.name), getSerializer(type, context.options.customSerializers[type.name])); | ||
body += getSerializerName(type.name); | ||
@@ -663,7 +663,8 @@ body += `(${originPaths.join(".")}, (message) => {${errorDestination}.push(${getErrorObject(fieldNodes, previousPath, "message")});})`; | ||
* @param {GraphQLScalarType | GraphQLEnumType} scalar | ||
* @param customSerializer custom serializer | ||
* @returns {(v: any) => any} bound serializationFunction | ||
*/ | ||
function getSerializer(scalar) { | ||
function getSerializer(scalar, customSerializer) { | ||
const { name } = scalar; | ||
const serialize = scalar.serialize.bind(scalar); | ||
const serialize = customSerializer ? customSerializer : (val) => scalar.serialize(val); | ||
return (v, onError) => { | ||
@@ -670,0 +671,0 @@ try { |
{ | ||
"name": "graphql-jit", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "GraphQL JIT Compiler to JS", | ||
@@ -36,2 +36,10 @@ "main": "dist/index.js", | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 87, | ||
"functions": 93, | ||
"lines": 93, | ||
"statements": 93 | ||
} | ||
} | ||
@@ -38,0 +46,0 @@ }, |
@@ -41,3 +41,3 @@ # GraphQL JIT | ||
module.exports = function setupHandler(schema, disableLeafSerialization) { | ||
module.exports = function setupHandler(schema) { | ||
const cache = LRU({max: 100}); | ||
@@ -107,3 +107,3 @@ return function graphqlMiddleware(request, response) { | ||
cached = compileQuery(schema, documentAST, operationName, {disableLeafSerialization}); | ||
cached = compileQuery(schema, documentAST, operationName, {customSerializers: {ID: String, String: String}}); | ||
cache.set(query + operationName, cached) | ||
@@ -165,2 +165,4 @@ } | ||
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 | ||
- `customJSONSerializer` {boolean, default: false} - Whether to produce also a JSON serializer function using `fast-json-stringify`, | ||
@@ -167,0 +169,0 @@ otherwise the stringify function is just `JSON.stringify` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125351
1860
180