@contember/graphql-utils
Advanced tools
Comparing version 2.0.0-alpha.12 to 2.0.0-alpha.13
import { DateTimeType } from "./src/DateTimeType.js"; | ||
import { JSONType } from "./src/JsonType.js"; | ||
import { JSONType, createJsonLikeType } from "./src/JsonType.js"; | ||
import { ForbiddenError, UserInputError } from "./src/errors.js"; | ||
@@ -10,4 +10,5 @@ import { UuidType } from "./src/UuidType.js"; | ||
UserInputError, | ||
UuidType | ||
UuidType, | ||
createJsonLikeType | ||
}; | ||
//# sourceMappingURL=index.js.map |
import { GraphQLScalarType, Kind } from "graphql"; | ||
const JSONType = new GraphQLScalarType({ | ||
name: "Json", | ||
description: "Json custom scalar type", | ||
serialize(value) { | ||
return value; | ||
}, | ||
parseValue(value) { | ||
return value; | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast2, variables2) => { | ||
switch (ast2.kind) { | ||
case Kind.STRING: | ||
return ast2.value; | ||
case Kind.BOOLEAN: | ||
return ast2.value; | ||
case Kind.FLOAT: | ||
return parseFloat(ast2.value); | ||
case Kind.INT: | ||
return Number(ast2.value); | ||
case Kind.LIST: | ||
return ast2.values.map((it) => parseLiteral(it, variables2)); | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast2.fields.map((it) => [it.name.value, parseLiteral(it.value, variables2)])); | ||
case Kind.NULL: | ||
return null; | ||
case Kind.VARIABLE: | ||
return variables2?.[ast2.name.value] || void 0; | ||
default: | ||
throw new TypeError(); | ||
} | ||
}; | ||
return parseLiteral(ast, variables); | ||
} | ||
}); | ||
const createJsonLikeType = (name, description) => { | ||
return new GraphQLScalarType({ | ||
name, | ||
description, | ||
serialize(value) { | ||
return value; | ||
}, | ||
parseValue(value) { | ||
return value; | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast2, variables2) => { | ||
switch (ast2.kind) { | ||
case Kind.STRING: | ||
return ast2.value; | ||
case Kind.BOOLEAN: | ||
return ast2.value; | ||
case Kind.FLOAT: | ||
return parseFloat(ast2.value); | ||
case Kind.INT: | ||
return Number(ast2.value); | ||
case Kind.LIST: | ||
return ast2.values.map((it) => parseLiteral(it, variables2)); | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast2.fields.map((it) => [it.name.value, parseLiteral(it.value, variables2)])); | ||
case Kind.NULL: | ||
return null; | ||
case Kind.VARIABLE: | ||
return variables2?.[ast2.name.value] || void 0; | ||
default: | ||
throw new TypeError(); | ||
} | ||
}; | ||
return parseLiteral(ast, variables); | ||
} | ||
}); | ||
}; | ||
const JSONType = createJsonLikeType("Json", "JSON custom scalar type"); | ||
export { | ||
JSONType | ||
JSONType, | ||
createJsonLikeType | ||
}; | ||
//# sourceMappingURL=JsonType.js.map |
import { DateTimeType } from "./src/DateTimeType.js"; | ||
import { JSONType } from "./src/JsonType.js"; | ||
import { JSONType, createJsonLikeType } from "./src/JsonType.js"; | ||
import { ForbiddenError, UserInputError } from "./src/errors.js"; | ||
@@ -10,4 +10,5 @@ import { UuidType } from "./src/UuidType.js"; | ||
UserInputError, | ||
UuidType | ||
UuidType, | ||
createJsonLikeType | ||
}; | ||
//# sourceMappingURL=index.js.map |
import { GraphQLScalarType, Kind } from "graphql"; | ||
const JSONType = new GraphQLScalarType({ | ||
name: "Json", | ||
description: "Json custom scalar type", | ||
serialize(value) { | ||
return value; | ||
}, | ||
parseValue(value) { | ||
return value; | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast2, variables2) => { | ||
switch (ast2.kind) { | ||
case Kind.STRING: | ||
return ast2.value; | ||
case Kind.BOOLEAN: | ||
return ast2.value; | ||
case Kind.FLOAT: | ||
return parseFloat(ast2.value); | ||
case Kind.INT: | ||
return Number(ast2.value); | ||
case Kind.LIST: | ||
return ast2.values.map((it) => parseLiteral(it, variables2)); | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast2.fields.map((it) => [it.name.value, parseLiteral(it.value, variables2)])); | ||
case Kind.NULL: | ||
return null; | ||
case Kind.VARIABLE: | ||
return variables2?.[ast2.name.value] || void 0; | ||
default: | ||
throw new TypeError(); | ||
} | ||
}; | ||
return parseLiteral(ast, variables); | ||
} | ||
}); | ||
const createJsonLikeType = (name, description) => { | ||
return new GraphQLScalarType({ | ||
name, | ||
description, | ||
serialize(value) { | ||
return value; | ||
}, | ||
parseValue(value) { | ||
return value; | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast2, variables2) => { | ||
switch (ast2.kind) { | ||
case Kind.STRING: | ||
return ast2.value; | ||
case Kind.BOOLEAN: | ||
return ast2.value; | ||
case Kind.FLOAT: | ||
return parseFloat(ast2.value); | ||
case Kind.INT: | ||
return Number(ast2.value); | ||
case Kind.LIST: | ||
return ast2.values.map((it) => parseLiteral(it, variables2)); | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast2.fields.map((it) => [it.name.value, parseLiteral(it.value, variables2)])); | ||
case Kind.NULL: | ||
return null; | ||
case Kind.VARIABLE: | ||
return variables2?.[ast2.name.value] || void 0; | ||
default: | ||
throw new TypeError(); | ||
} | ||
}; | ||
return parseLiteral(ast, variables); | ||
} | ||
}); | ||
}; | ||
const JSONType = createJsonLikeType("Json", "JSON custom scalar type"); | ||
export { | ||
JSONType | ||
JSONType, | ||
createJsonLikeType | ||
}; | ||
//# sourceMappingURL=JsonType.js.map |
import { GraphQLScalarType } from 'graphql'; | ||
export declare const createJsonLikeType: (name: string, description: string) => GraphQLScalarType<unknown, unknown>; | ||
export declare const JSONType: GraphQLScalarType<unknown, unknown>; | ||
//# sourceMappingURL=JsonType.d.ts.map |
{ | ||
"name": "@contember/graphql-utils", | ||
"version": "2.0.0-alpha.12", | ||
"version": "2.0.0-alpha.13", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "main": "./dist/production/index.js", |
@@ -6,36 +6,41 @@ import { JSONValue } from './json' | ||
export const JSONType = new GraphQLScalarType({ | ||
name: 'Json', | ||
description: 'Json custom scalar type', | ||
serialize(value) { | ||
return value | ||
}, | ||
parseValue(value) { | ||
return value | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast: ValueNode, variables: Maybe<{ [key: string]: any }>): JSONValue => { | ||
switch (ast.kind) { | ||
case Kind.STRING: | ||
return ast.value | ||
case Kind.BOOLEAN: | ||
return ast.value | ||
case Kind.FLOAT: | ||
return parseFloat(ast.value) | ||
case Kind.INT: | ||
return Number(ast.value) | ||
case Kind.LIST: | ||
return ast.values.map(it => parseLiteral(it, variables)) | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast.fields.map(it => [it.name.value, parseLiteral(it.value, variables)])) | ||
case Kind.NULL: | ||
return null | ||
case Kind.VARIABLE: | ||
return variables?.[ast.name.value] || undefined | ||
default: | ||
throw new TypeError() | ||
export const createJsonLikeType = (name: string, description: string) => { | ||
return new GraphQLScalarType({ | ||
name, | ||
description, | ||
serialize(value) { | ||
return value | ||
}, | ||
parseValue(value) { | ||
return value | ||
}, | ||
parseLiteral(ast, variables) { | ||
const parseLiteral = (ast: ValueNode, variables: Maybe<{ [key: string]: any }>): JSONValue => { | ||
switch (ast.kind) { | ||
case Kind.STRING: | ||
return ast.value | ||
case Kind.BOOLEAN: | ||
return ast.value | ||
case Kind.FLOAT: | ||
return parseFloat(ast.value) | ||
case Kind.INT: | ||
return Number(ast.value) | ||
case Kind.LIST: | ||
return ast.values.map(it => parseLiteral(it, variables)) | ||
case Kind.OBJECT: | ||
return Object.fromEntries(ast.fields.map(it => [it.name.value, parseLiteral(it.value, variables)])) | ||
case Kind.NULL: | ||
return null | ||
case Kind.VARIABLE: | ||
return variables?.[ast.name.value] || undefined | ||
default: | ||
throw new TypeError() | ||
} | ||
} | ||
} | ||
return parseLiteral(ast, variables) | ||
}, | ||
}) | ||
return parseLiteral(ast, variables) | ||
}, | ||
}) | ||
} | ||
export const JSONType = createJsonLikeType('Json', 'JSON custom scalar type') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
110543
644