From 0fb119aa21ef552ed00a65ea7ab813ff06473cc6 Mon Sep 17 00:00:00 2001 From: Liam Tait Date: Thu, 18 May 2023 20:22:24 +1200 Subject: [PATCH] fix: remove explicit type for GraphQLScalarType (#1920) Removing the explicit type helps with type inference. For example Before this change `GraphQLDate` is of type `GraphQLScalarType` After this change `GraphQLDate` is of type `GraphQLScalarType` The alternative to this is to duplicate the types from the `GraphQLScalarTypeConfig` By adding the `TInternal` and `TExternal` generics to the explicit type These types are useful when adding scalars with a code first apporach such as in @pothos/core where scalar types are defined for the `SchemaBuilder` Co-authored-by: James Macfie --- src/scalars/AccountNumber.ts | 9 ++-- src/scalars/BigInt.ts | 4 +- src/scalars/Byte.ts | 75 +++++++++++++++++------------ src/scalars/CountryCode.ts | 17 ++++--- src/scalars/Cuid.ts | 8 +-- src/scalars/Currency.ts | 13 +++-- src/scalars/DID.ts | 13 +++-- src/scalars/EmailAddress.ts | 4 +- src/scalars/GUID.ts | 2 +- src/scalars/HSL.ts | 19 +++++--- src/scalars/HSLA.ts | 13 +++-- src/scalars/HexColorCode.ts | 14 ++++-- src/scalars/Hexadecimal.ts | 14 ++++-- src/scalars/IBAN.ts | 9 ++-- src/scalars/IP.ts | 13 +++-- src/scalars/IPv4.ts | 14 ++++-- src/scalars/IPv6.ts | 14 ++++-- src/scalars/ISBN.ts | 13 +++-- src/scalars/JWT.ts | 11 +++-- src/scalars/Latitude.ts | 23 ++++++--- src/scalars/LocalDate.ts | 24 ++++++--- src/scalars/LocalEndTime.ts | 8 +-- src/scalars/LocalTime.ts | 13 +++-- src/scalars/Locale.ts | 9 ++-- src/scalars/Long.ts | 2 +- src/scalars/Longitude.ts | 25 +++++++--- src/scalars/MAC.ts | 17 +++++-- src/scalars/NegativeFloat.ts | 6 +-- src/scalars/NegativeInt.ts | 13 +++-- src/scalars/NonEmptyString.ts | 9 ++-- src/scalars/NonNegativeFloat.ts | 8 +-- src/scalars/NonNegativeInt.ts | 15 +++--- src/scalars/NonPositiveFloat.ts | 6 +-- src/scalars/NonPositiveInt.ts | 13 +++-- src/scalars/ObjectID.ts | 17 ++++--- src/scalars/PhoneNumber.ts | 19 +++++--- src/scalars/Port.ts | 18 +++++-- src/scalars/PositiveFloat.ts | 6 +-- src/scalars/PositiveInt.ts | 13 +++-- src/scalars/PostalCode.ts | 8 +-- src/scalars/RGB.ts | 13 +++-- src/scalars/RGBA.ts | 13 +++-- src/scalars/RoutingNumber.ts | 11 +++-- src/scalars/SafeInt.ts | 16 +++--- src/scalars/SemVer.ts | 14 ++++-- src/scalars/TimeZone.ts | 11 +++-- src/scalars/Timestamp.ts | 2 +- src/scalars/URL.ts | 8 +-- src/scalars/USCurrency.ts | 17 ++++--- src/scalars/UUID.ts | 13 +++-- src/scalars/UnsignedFloat.ts | 2 +- src/scalars/UnsignedInt.ts | 2 +- src/scalars/UtcOffset.ts | 16 ++++-- src/scalars/Void.ts | 2 +- src/scalars/iso-date/Date.ts | 20 +++++--- src/scalars/iso-date/DateTime.ts | 32 +++++++----- src/scalars/iso-date/Duration.ts | 9 ++-- src/scalars/iso-date/Time.ts | 23 ++++++--- src/scalars/json/JSON.ts | 3 +- src/scalars/json/JSONObject.ts | 2 +- src/scalars/library/DeweyDecimal.ts | 11 +++-- src/scalars/library/LCCSubclass.ts | 9 ++-- src/scalars/patent/IPCPatent.ts | 4 +- 63 files changed, 518 insertions(+), 286 deletions(-) diff --git a/src/scalars/AccountNumber.ts b/src/scalars/AccountNumber.ts index fd7aa5ddf..ece620aeb 100644 --- a/src/scalars/AccountNumber.ts +++ b/src/scalars/AccountNumber.ts @@ -17,7 +17,7 @@ const validate = (account: unknown, ast?: ValueNode): string => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -28,7 +28,7 @@ const validate = (account: unknown, ast?: ValueNode): string => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -38,7 +38,8 @@ const validate = (account: unknown, ast?: ValueNode): string => { export const GraphQLAccountNumberConfig: GraphQLScalarTypeConfig = { name: 'AccountNumber', description: - 'Banking account number is a string of 5 to 17 alphanumeric values for ' + 'representing an generic account number', + 'Banking account number is a string of 5 to 17 alphanumeric values for ' + + 'representing an generic account number', serialize(value: unknown) { return validate(value); @@ -67,4 +68,4 @@ export const GraphQLAccountNumberConfig: GraphQLScalarTypeConfig }, }; -export const GraphQLAccountNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLAccountNumberConfig); +export const GraphQLAccountNumber = /*#__PURE__*/ new GraphQLScalarType(GraphQLAccountNumberConfig); diff --git a/src/scalars/BigInt.ts b/src/scalars/BigInt.ts index bf4ce8f40..78da258d7 100644 --- a/src/scalars/BigInt.ts +++ b/src/scalars/BigInt.ts @@ -97,6 +97,4 @@ export const GraphQLBigIntConfig: GraphQLScalarTypeConfig< }, }; -export const GraphQLBigInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( - GraphQLBigIntConfig, -); +export const GraphQLBigInt = /*#__PURE__*/ new GraphQLScalarType(GraphQLBigIntConfig); diff --git a/src/scalars/Byte.ts b/src/scalars/Byte.ts index 9d2ff0ae1..2e783c02d 100644 --- a/src/scalars/Byte.ts +++ b/src/scalars/Byte.ts @@ -19,7 +19,11 @@ function hexValidator(value: string) { // into smaller pieces to avoid this issue. if (value.length > 8) { let parsedString = ''; - for (let startIndex = 0, endIndex = 8; startIndex < value.length; startIndex += 8, endIndex += 8) { + for ( + let startIndex = 0, endIndex = 8; + startIndex < value.length; + startIndex += 8, endIndex += 8 + ) { parsedString += parseInt(value.slice(startIndex, endIndex), 16).toString(16); } return parsedString === sanitizedValue; @@ -35,7 +39,7 @@ function validate(value: Buffer | string | BufferJson, ast?: ValueNode) { ? { nodes: ast, } - : undefined + : undefined, ); } if (typeof value === 'string') { @@ -48,7 +52,7 @@ function validate(value: Buffer | string | BufferJson, ast?: ValueNode) { ? { nodes: ast, } - : undefined + : undefined, ); } return global.Buffer.from(value, isHex ? 'hex' : 'base64'); @@ -60,38 +64,49 @@ function validate(value: Buffer | string | BufferJson, ast?: ValueNode) { function parseObject(ast: ObjectValueNode) { const key = ast.fields[0].value; const value = ast.fields[1].value; - if (ast.fields.length === 2 && key.kind === Kind.STRING && key.value === 'Buffer' && value.kind === Kind.LIST) { - return global.Buffer.from(value.values.map((astValue: IntValueNode) => parseInt(astValue.value))); + if ( + ast.fields.length === 2 && + key.kind === Kind.STRING && + key.value === 'Buffer' && + value.kind === Kind.LIST + ) { + return global.Buffer.from( + value.values.map((astValue: IntValueNode) => parseInt(astValue.value)), + ); } throw createGraphQLError(`Value is not a JSON representation of Buffer: ${print(ast)}`, { nodes: [ast], }); } -export const GraphQLByteConfig: GraphQLScalarTypeConfig = /*#__PURE__*/ { - name: 'Byte', - description: 'The `Byte` scalar type represents byte value as a Buffer', - serialize: validate, - parseValue: validate, - parseLiteral(ast: ASTNode) { - switch (ast.kind) { - case Kind.STRING: - return validate(ast.value, ast); - case Kind.OBJECT: - return parseObject(ast); - default: - throw createGraphQLError(`Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`, { - nodes: [ast], - }); - } - }, - extensions: { - codegenScalarType: 'Buffer | string', - jsonSchema: { - type: 'string', - format: 'byte', +export const GraphQLByteConfig: GraphQLScalarTypeConfig = + /*#__PURE__*/ { + name: 'Byte', + description: 'The `Byte` scalar type represents byte value as a Buffer', + serialize: validate, + parseValue: validate, + parseLiteral(ast: ASTNode) { + switch (ast.kind) { + case Kind.STRING: + return validate(ast.value, ast); + case Kind.OBJECT: + return parseObject(ast); + default: + throw createGraphQLError( + `Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`, + { + nodes: [ast], + }, + ); + } + }, + extensions: { + codegenScalarType: 'Buffer | string', + jsonSchema: { + type: 'string', + format: 'byte', + }, }, - }, -}; + }; -export const GraphQLByte: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLByteConfig); +export const GraphQLByte = /*#__PURE__*/ new GraphQLScalarType(GraphQLByteConfig); diff --git a/src/scalars/CountryCode.ts b/src/scalars/CountryCode.ts index 655bdb6b7..3a3dc61f2 100644 --- a/src/scalars/CountryCode.ts +++ b/src/scalars/CountryCode.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ValueNode } from 'graphql'; +import { GraphQLScalarType, Kind, ValueNode } from 'graphql'; import { createGraphQLError } from '../error.js'; const COUNTRY_CODE_REGEX = @@ -12,7 +12,7 @@ const validate = (value: any, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -23,13 +23,13 @@ const validate = (value: any, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } return value; }; -export const GraphQLCountryCode: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLCountryCode = /*#__PURE__*/ new GraphQLScalarType({ name: 'CountryCode', description: 'A country code as defined by ISO 3166-1 alpha-2', serialize(value) { @@ -42,9 +42,12 @@ export const GraphQLCountryCode: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as country codes but got a: ${ast.kind}`, { - nodes: [ast], - }); + throw createGraphQLError( + `Can only validate strings as country codes but got a: ${ast.kind}`, + { + nodes: [ast], + }, + ); } return validate(ast.value, ast); }, diff --git a/src/scalars/Cuid.ts b/src/scalars/Cuid.ts index 99d241d63..2694119c4 100644 --- a/src/scalars/Cuid.ts +++ b/src/scalars/Cuid.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ValueNode } from 'graphql'; +import { GraphQLScalarType, GraphQLScalarTypeConfig, Kind, ValueNode } from 'graphql'; import { createGraphQLError } from '../error.js'; const CUID_REGEX = /^c[^\s-]{8,}$/i; @@ -11,7 +11,7 @@ const validate = (value: any, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -22,7 +22,7 @@ const validate = (value: any, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -63,4 +63,4 @@ export const GraphQLCuidConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLCuid: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLCuidConfig); +export const GraphQLCuid = /*#__PURE__*/ new GraphQLScalarType(GraphQLCuidConfig); diff --git a/src/scalars/Currency.ts b/src/scalars/Currency.ts index d150d3544..5a176821d 100644 --- a/src/scalars/Currency.ts +++ b/src/scalars/Currency.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const CURRENCY_REGEX = @@ -10,7 +10,10 @@ const validate = (value: any, ast?: ASTNode) => { } if (!CURRENCY_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid currency value: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid currency value: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; @@ -33,7 +36,9 @@ export const GraphQLCurrencyConfig = /*#__PURE__*/ { parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as a currency but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as a currency but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); @@ -51,4 +56,4 @@ export const GraphQLCurrencyConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLCurrency: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLCurrencyConfig); +export const GraphQLCurrency = /*#__PURE__*/ new GraphQLScalarType(GraphQLCurrencyConfig); diff --git a/src/scalars/DID.ts b/src/scalars/DID.ts index 5f7203355..77b26e74d 100644 --- a/src/scalars/DID.ts +++ b/src/scalars/DID.ts @@ -1,4 +1,4 @@ -import { GraphQLScalarType, Kind, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; // See: https://www.w3.org/TR/2021/PR-did-core-20210803/#did-syntax @@ -11,7 +11,10 @@ const validate = (value: any, ast?: ASTNode) => { } if (!DID_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid DID: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid DID: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; @@ -31,7 +34,9 @@ export const GraphQLDIDConfig = { parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as DID but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as DID but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); @@ -49,4 +54,4 @@ export const GraphQLDIDConfig = { }, } as GraphQLScalarTypeConfig; -export const GraphQLDID: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLDIDConfig); +export const GraphQLDID = /*#__PURE__*/ new GraphQLScalarType(GraphQLDIDConfig); diff --git a/src/scalars/EmailAddress.ts b/src/scalars/EmailAddress.ts index f23542dcd..a0d53672c 100644 --- a/src/scalars/EmailAddress.ts +++ b/src/scalars/EmailAddress.ts @@ -50,6 +50,4 @@ export const GraphQLEmailAddressConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLEmailAddress: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( - GraphQLEmailAddressConfig, -); +export const GraphQLEmailAddress = /*#__PURE__*/ new GraphQLScalarType(GraphQLEmailAddressConfig); diff --git a/src/scalars/GUID.ts b/src/scalars/GUID.ts index 841cc9978..642940658 100644 --- a/src/scalars/GUID.ts +++ b/src/scalars/GUID.ts @@ -5,4 +5,4 @@ export const GraphQLGUIDConfig = /*#__PURE__*/ Object.assign({}, GraphQLUUIDConf name: 'GUID', }); -export const GraphQLGUID: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLGUIDConfig); +export const GraphQLGUID = /*#__PURE__*/ new GraphQLScalarType(GraphQLGUIDConfig); diff --git a/src/scalars/HSL.ts b/src/scalars/HSL.ts index 5e0c23e3e..ff314b93a 100644 --- a/src/scalars/HSL.ts +++ b/src/scalars/HSL.ts @@ -1,7 +1,8 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; -const HSL_REGEX = /^hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)$/; +const HSL_REGEX = + /^hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)$/; const validate = (value: any, ast?: ASTNode) => { if (typeof value !== 'string') { @@ -9,13 +10,17 @@ const validate = (value: any, ast?: ASTNode) => { } if (!HSL_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid HSL color: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid HSL color: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -const specifiedByURL = 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla()'; +const specifiedByURL = + 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla()'; export const GraphQLHSLConfig: GraphQLScalarTypeConfig = /*#__PURE__*/ { name: `HSL`, @@ -32,7 +37,9 @@ export const GraphQLHSLConfig: GraphQLScalarTypeConfig = /*#__PU parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as HSL colors but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as HSL colors but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); @@ -50,4 +57,4 @@ export const GraphQLHSLConfig: GraphQLScalarTypeConfig = /*#__PU }, } as GraphQLScalarTypeConfig; -export const GraphQLHSL: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLHSLConfig); +export const GraphQLHSL = /*#__PURE__*/ new GraphQLScalarType(GraphQLHSLConfig); diff --git a/src/scalars/HSLA.ts b/src/scalars/HSLA.ts index 3e5623f3b..8ea5ece3f 100644 --- a/src/scalars/HSLA.ts +++ b/src/scalars/HSLA.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const HSLA_REGEX = @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!HSLA_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid HSLA color: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid HSLA color: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLHSLA: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLHSLA = /*#__PURE__*/ new GraphQLScalarType({ name: `HSLA`, description: `A field whose value is a CSS HSLA color: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla().`, @@ -31,7 +34,9 @@ export const GraphQLHSLA: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as HSLA colors but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as HSLA colors but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/HexColorCode.ts b/src/scalars/HexColorCode.ts index 3ca316128..7076eabfe 100644 --- a/src/scalars/HexColorCode.ts +++ b/src/scalars/HexColorCode.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const HEX_COLOR_CODE = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/; @@ -9,7 +9,10 @@ const validate = (value: any, ast?: ASTNode) => { } if (!HEX_COLOR_CODE.test(value)) { - throw createGraphQLError(`Value is not a valid HexColorCode: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid HexColorCode: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; @@ -32,7 +35,10 @@ export const GraphQLHexColorCodeConfig = /*#__PURE__*/ { parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as hex color codes but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as hex color codes but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); @@ -50,4 +56,4 @@ export const GraphQLHexColorCodeConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLHexColorCode: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLHexColorCodeConfig); +export const GraphQLHexColorCode = /*#__PURE__*/ new GraphQLScalarType(GraphQLHexColorCodeConfig); diff --git a/src/scalars/Hexadecimal.ts b/src/scalars/Hexadecimal.ts index 38581df1c..c3e67ed90 100644 --- a/src/scalars/Hexadecimal.ts +++ b/src/scalars/Hexadecimal.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const HEXADECIMAL_REGEX = /^[a-f0-9]+$/i; @@ -8,7 +8,10 @@ const validate = (value: any, ast?: ASTNode) => { } if (!HEXADECIMAL_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid hexadecimal value: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid hexadecimal value: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; @@ -29,7 +32,10 @@ export const GraphQLHexadecimalConfig: GraphQLScalarTypeConfig = parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as a hexadecimal but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as a hexadecimal but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); @@ -44,4 +50,4 @@ export const GraphQLHexadecimalConfig: GraphQLScalarTypeConfig = }, }; -export const GraphQLHexadecimal: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLHexadecimalConfig); +export const GraphQLHexadecimal = /*#__PURE__*/ new GraphQLScalarType(GraphQLHexadecimalConfig); diff --git a/src/scalars/IBAN.ts b/src/scalars/IBAN.ts index 6f1e9b9a5..58871a89c 100644 --- a/src/scalars/IBAN.ts +++ b/src/scalars/IBAN.ts @@ -1,6 +1,5 @@ // Based on https://github.com/arhs/iban.js - -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; interface Specification { @@ -388,7 +387,7 @@ function validate(iban: string): boolean { return !!countryStructure && _testIBAN(iban, countryCode, countryStructure); } -export const GraphQLIBAN: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLIBAN = /*#__PURE__*/ new GraphQLScalarType({ name: `IBAN`, description: `A field whose value is an International Bank Account Number (IBAN): https://en.wikipedia.org/wiki/International_Bank_Account_Number.`, serialize(value: string) { @@ -417,7 +416,9 @@ export const GraphQLIBAN: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast: { kind: any; value: string }) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as IBANs but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as IBANs but got a: ${ast.kind}`, { + nodes: ast, + }); } if (!validate(ast.value)) { diff --git a/src/scalars/IP.ts b/src/scalars/IP.ts index 48cb14951..4b9f497d9 100644 --- a/src/scalars/IP.ts +++ b/src/scalars/IP.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { IPV4_REGEX } from './IPv4.js'; import { IPV6_REGEX } from './IPv6.js'; @@ -9,13 +9,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!IPV4_REGEX.test(value) && !IPV6_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid IPv4 or IPv6 address: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid IPv4 or IPv6 address: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLIP: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLIP = /*#__PURE__*/ new GraphQLScalarType({ name: `IP`, description: `A field whose value is either an IPv4 or IPv6 address: https://en.wikipedia.org/wiki/IP_address.`, @@ -30,7 +33,9 @@ export const GraphQLIP: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as IP addresses but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as IP addresses but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/IPv4.ts b/src/scalars/IPv4.ts index a8ac60420..f04b1f37a 100644 --- a/src/scalars/IPv4.ts +++ b/src/scalars/IPv4.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; export const IPV4_REGEX = @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!IPV4_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid IPv4 address: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid IPv4 address: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLIPv4: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLIPv4 = /*#__PURE__*/ new GraphQLScalarType({ name: `IPv4`, description: `A field whose value is a IPv4 address: https://en.wikipedia.org/wiki/IPv4.`, @@ -31,7 +34,10 @@ export const GraphQLIPv4: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as IPv4 addresses but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as IPv4 addresses but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/IPv6.ts b/src/scalars/IPv6.ts index 1cfeffe36..be7955250 100644 --- a/src/scalars/IPv6.ts +++ b/src/scalars/IPv6.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; export const IPV6_REGEX = @@ -9,13 +9,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!IPV6_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid IPv6 address: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid IPv6 address: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLIPv6: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLIPv6 = /*#__PURE__*/ new GraphQLScalarType({ name: `IPv6`, description: `A field whose value is a IPv6 address: https://en.wikipedia.org/wiki/IPv6.`, @@ -30,7 +33,10 @@ export const GraphQLIPv6: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as IPv6 addresses but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as IPv6 addresses but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/ISBN.ts b/src/scalars/ISBN.ts index 8ac37a95f..179d80916 100644 --- a/src/scalars/ISBN.ts +++ b/src/scalars/ISBN.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const ISBN_REGEX_ARR = [ @@ -20,13 +20,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!valid) { - throw createGraphQLError(`Value is not a valid ISBN number: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid ISBN number: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLISBN: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLISBN = /*#__PURE__*/ new GraphQLScalarType({ name: `ISBN`, description: `A field whose value is a ISBN-10 or ISBN-13 number: https://en.wikipedia.org/wiki/International_Standard_Book_Number.`, @@ -41,7 +44,9 @@ export const GraphQLISBN: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as ISBN numbers but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as ISBN numbers but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/JWT.ts b/src/scalars/JWT.ts index bfc6b2b3e..fbfedde00 100644 --- a/src/scalars/JWT.ts +++ b/src/scalars/JWT.ts @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!JWS_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid JWT: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid JWT: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLJWT: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLJWT = /*#__PURE__*/ new GraphQLScalarType({ name: `JWT`, description: `A field whose value is a JSON Web Token (JWT): https://jwt.io/introduction.`, @@ -31,7 +34,9 @@ export const GraphQLJWT: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as JWT but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as JWT but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/Latitude.ts b/src/scalars/Latitude.ts index 0d7b0a33c..58fc8c0ac 100644 --- a/src/scalars/Latitude.ts +++ b/src/scalars/Latitude.ts @@ -18,7 +18,10 @@ const validate = (value: any, ast?: ASTNode): number => { typeof value === 'undefined' || Number.isNaN(value) ) { - throw createGraphQLError(`Value is neither a number nor a string: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is neither a number nor a string: ${value}`, + ast ? { nodes: ast } : undefined, + ); } if (isDecimal(value)) { @@ -27,7 +30,7 @@ const validate = (value: any, ast?: ASTNode): number => { if (decimalValue < MIN_LAT || decimalValue > MAX_LAT) { throw createGraphQLError( `Value must be between ${MIN_LAT} and ${MAX_LAT}: ${value}`, - ast ? { nodes: ast } : undefined + ast ? { nodes: ast } : undefined, ); } @@ -38,10 +41,13 @@ const validate = (value: any, ast?: ASTNode): number => { return validate(sexagesimalToDecimal(value)); } - throw createGraphQLError(`Value is not a valid latitude: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid latitude: ${value}`, + ast ? { nodes: ast } : undefined, + ); }; -export const GraphQLLatitude: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLatitude = /*#__PURE__*/ new GraphQLScalarType({ name: `Latitude`, description: `A field whose value is a valid decimal degrees latitude number (53.471): https://en.wikipedia.org/wiki/Latitude`, @@ -56,9 +62,12 @@ export const GraphQLLatitude: GraphQLScalarType = /*#__PURE__*/ new GraphQLScala parseLiteral(ast) { if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate floats or strings as latitude but got a: ${ast.kind}`, { - nodes: [ast], - }); + throw createGraphQLError( + `Can only validate floats or strings as latitude but got a: ${ast.kind}`, + { + nodes: [ast], + }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/LocalDate.ts b/src/scalars/LocalDate.ts index 267bff53d..51a2c68ba 100644 --- a/src/scalars/LocalDate.ts +++ b/src/scalars/LocalDate.ts @@ -11,14 +11,20 @@ function validateLocalDate(value: any, ast?: ASTNode) { // check that it's in the `yyyy-MM-dd` format const isValidFormat = LOCAL_DATE_FORMAT.test(value); if (!isValidFormat) { - throw createGraphQLError(`Value is not a valid LocalDate: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid LocalDate: ${value}`, + ast ? { nodes: ast } : undefined, + ); } // check that it appears to be a valid date, e.g., not something like `2020-13-46` const valueAsDate = new Date(value); const isValidDate = !isNaN(valueAsDate.getTime()); if (!isValidDate) { - throw createGraphQLError(`Value is not a valid LocalDate: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid LocalDate: ${value}`, + ast ? { nodes: ast } : undefined, + ); } // some additional logic to catch invalid dates like `2020-02-30` @@ -26,15 +32,19 @@ function validateLocalDate(value: any, ast?: ASTNode) { // the original value const isCalendarDate = valueAsDate.toISOString() === `${value}T00:00:00.000Z`; if (!isCalendarDate) { - throw createGraphQLError(`Value is not a valid LocalDate: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid LocalDate: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; } -export const GraphQLLocalDate: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLocalDate = /*#__PURE__*/ new GraphQLScalarType({ name: 'LocalDate', - description: 'A local date string (i.e., with no associated timezone) in `YYYY-MM-DD` format, e.g. `2020-01-01`.', + description: + 'A local date string (i.e., with no associated timezone) in `YYYY-MM-DD` format, e.g. `2020-01-01`.', serialize(value) { // value sent to client as string @@ -49,7 +59,9 @@ export const GraphQLLocalDate: GraphQLScalarType = /*#__PURE__*/ new GraphQLScal parseLiteral(ast) { // value from client in ast if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as local dates but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as local dates but got a: ${ast.kind}`, { + nodes: ast, + }); } return validateLocalDate(ast.value, ast); diff --git a/src/scalars/LocalEndTime.ts b/src/scalars/LocalEndTime.ts index e5fb3df49..38fcb61ed 100644 --- a/src/scalars/LocalEndTime.ts +++ b/src/scalars/LocalEndTime.ts @@ -1,6 +1,6 @@ import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; -import { validateLocalTime, LOCAL_TIME_FORMAT } from './LocalTime.js'; +import { LOCAL_TIME_FORMAT, validateLocalTime } from './LocalTime.js'; const LOCAL_END_TIMES = ['24:00', '24:00:00', '24:00:00.000']; @@ -14,7 +14,7 @@ function validateLocalEndTime(value: any) { return validateLocalTime(value); } -export const GraphQLLocalEndTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLocalEndTime = /*#__PURE__*/ new GraphQLScalarType({ name: 'LocalEndTime', description: 'A local time string (i.e., with no associated timezone) in 24-hr `HH:mm[:ss[.SSS]]` format, e.g. `14:25` or `14:25:06` or `14:25:06.123`. This scalar is very similar to the `LocalTime`, with the only difference being that `LocalEndTime` also allows `24:00` as a valid value to indicate midnight of the following day. This is useful when using the scalar to represent the exclusive upper bound of a time block.', @@ -32,7 +32,9 @@ export const GraphQLLocalEndTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLS parseLiteral(ast) { // value from client in ast if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as local times but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as local times but got a: ${ast.kind}`, { + nodes: ast, + }); } return validateLocalEndTime(ast.value); diff --git a/src/scalars/LocalTime.ts b/src/scalars/LocalTime.ts index 8cfcb6906..d7711fbce 100644 --- a/src/scalars/LocalTime.ts +++ b/src/scalars/LocalTime.ts @@ -1,4 +1,4 @@ -import { GraphQLScalarType, Kind, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; // 24-hour time with optional seconds and milliseconds - `HH:mm[:ss[.SSS]]` @@ -11,13 +11,16 @@ export function validateLocalTime(value: any, ast?: ASTNode) { const isValidFormat = LOCAL_TIME_FORMAT.test(value); if (!isValidFormat) { - throw createGraphQLError(`Value is not a valid LocalTime: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid LocalTime: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; } -export const GraphQLLocalTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLocalTime = /*#__PURE__*/ new GraphQLScalarType({ name: 'LocalTime', description: 'A local time string (i.e., with no associated timezone) in 24-hr `HH:mm[:ss[.SSS]]` format, e.g. `14:25` or `14:25:06` or `14:25:06.123`.', @@ -35,7 +38,9 @@ export const GraphQLLocalTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLScal parseLiteral(ast) { // value from client in ast if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as local times but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as local times but got a: ${ast.kind}`, { + nodes: ast, + }); } return validateLocalTime(ast.value, ast); diff --git a/src/scalars/Locale.ts b/src/scalars/Locale.ts index c456f882c..968794363 100644 --- a/src/scalars/Locale.ts +++ b/src/scalars/Locale.ts @@ -6,19 +6,22 @@ const BCP_47_REGEX = function validate(value: string, ast?: ASTNode) { if (!value) { - throw createGraphQLError(`Value is not a valid string. Received: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid string. Received: ${value}`, + ast ? { nodes: ast } : undefined, + ); } const isValidFormat = BCP_47_REGEX.test(value); if (!isValidFormat) { throw createGraphQLError( `Value is not a valid BCP-47 standard formatted string. Received: ${value}`, - ast ? { nodes: ast } : undefined + ast ? { nodes: ast } : undefined, ); } return value; } -export const GraphQLLocale: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLocale = /*#__PURE__*/ new GraphQLScalarType({ name: 'Locale', description: 'The locale in the format of a BCP 47 (RFC 5646) standard string', serialize: validate, diff --git a/src/scalars/Long.ts b/src/scalars/Long.ts index fda34d5ad..e07e2c8f9 100644 --- a/src/scalars/Long.ts +++ b/src/scalars/Long.ts @@ -5,4 +5,4 @@ export const GraphQLLongConfig = /*#__PURE__*/ Object.assign({}, GraphQLBigIntCo name: 'Long', }); -export const GraphQLLong: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLLongConfig); +export const GraphQLLong = /*#__PURE__*/ new GraphQLScalarType(GraphQLLongConfig); diff --git a/src/scalars/Longitude.ts b/src/scalars/Longitude.ts index 2d71e140e..7b58ba70c 100644 --- a/src/scalars/Longitude.ts +++ b/src/scalars/Longitude.ts @@ -1,7 +1,7 @@ // Inspired by Geolib: https://github.com/manuelbieh/geolib import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; -import { isDecimal, isSexagesimal, sexagesimalToDecimal } from './utilities.js'; import { createGraphQLError } from '../error.js'; +import { isDecimal, isSexagesimal, sexagesimalToDecimal } from './utilities.js'; // Minimum longitude const MIN_LON = -180.0; @@ -18,7 +18,10 @@ const validate = (value: any, ast?: ASTNode): number => { typeof value === 'undefined' || Number.isNaN(value) ) { - throw createGraphQLError(`Value is neither a number nor a string: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is neither a number nor a string: ${value}`, + ast ? { nodes: ast } : undefined, + ); } if (isDecimal(value)) { @@ -27,7 +30,7 @@ const validate = (value: any, ast?: ASTNode): number => { if (decimalValue < MIN_LON || decimalValue > MAX_LON) { throw createGraphQLError( `Value must be between ${MIN_LON} and ${MAX_LON}: ${value}`, - ast ? { nodes: ast } : undefined + ast ? { nodes: ast } : undefined, ); } @@ -38,10 +41,13 @@ const validate = (value: any, ast?: ASTNode): number => { return validate(sexagesimalToDecimal(value)); } - throw createGraphQLError(`Value is not a valid longitude: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid longitude: ${value}`, + ast ? { nodes: ast } : undefined, + ); }; -export const GraphQLLongitude: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLLongitude = /*#__PURE__*/ new GraphQLScalarType({ name: `Longitude`, description: `A field whose value is a valid decimal degrees longitude number (53.471): https://en.wikipedia.org/wiki/Longitude`, @@ -56,9 +62,12 @@ export const GraphQLLongitude: GraphQLScalarType = /*#__PURE__*/ new GraphQLScal parseLiteral(ast) { if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate floats or strings as longitude but got a: ${ast.kind}`, { - nodes: [ast], - }); + throw createGraphQLError( + `Can only validate floats or strings as longitude but got a: ${ast.kind}`, + { + nodes: [ast], + }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/MAC.ts b/src/scalars/MAC.ts index 4c627f3e4..d4168126f 100644 --- a/src/scalars/MAC.ts +++ b/src/scalars/MAC.ts @@ -1,7 +1,8 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; -const MAC_REGEX = /^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/; +const MAC_REGEX = + /^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/; const validate = (value: any, ast?: ASTNode) => { if (typeof value !== 'string') { @@ -9,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!MAC_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid MAC address: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid MAC address: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLMAC: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLMAC = /*#__PURE__*/ new GraphQLScalarType({ name: `MAC`, description: `A field whose value is a IEEE 802 48-bit MAC address: https://en.wikipedia.org/wiki/MAC_address.`, @@ -30,7 +34,10 @@ export const GraphQLMAC: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as MAC addresses but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as MAC addresses but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/NegativeFloat.ts b/src/scalars/NegativeFloat.ts index d571f7eeb..221c25c8d 100644 --- a/src/scalars/NegativeFloat.ts +++ b/src/scalars/NegativeFloat.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLNegativeFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLNegativeFloat = /*#__PURE__*/ new GraphQLScalarType({ name: 'NegativeFloat', description: 'Floats that will have a value less than 0.', @@ -19,7 +19,7 @@ export const GraphQLNegativeFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQL if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT) { throw createGraphQLError( `Can only validate floating point numbers as negative floating point numbers but got a: ${ast.kind}`, - { nodes: ast } + { nodes: ast }, ); } diff --git a/src/scalars/NegativeInt.ts b/src/scalars/NegativeInt.ts index 980b14f86..956c529e4 100644 --- a/src/scalars/NegativeInt.ts +++ b/src/scalars/NegativeInt.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLNegativeInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLNegativeInt = /*#__PURE__*/ new GraphQLScalarType({ name: 'NegativeInt', description: 'Integers that will have a value less than 0.', @@ -17,9 +17,12 @@ export const GraphQLNegativeInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc parseLiteral(ast) { if (ast.kind !== Kind.INT) { - throw createGraphQLError(`Can only validate integers as negative integers but got a: ${ast.kind}`, { - nodes: ast, - }); + throw createGraphQLError( + `Can only validate integers as negative integers but got a: ${ast.kind}`, + { + nodes: ast, + }, + ); } return processValue(ast.value, 'NegativeInt'); diff --git a/src/scalars/NonEmptyString.ts b/src/scalars/NonEmptyString.ts index 66814e59c..92c21c04b 100644 --- a/src/scalars/NonEmptyString.ts +++ b/src/scalars/NonEmptyString.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const validate = (value: any, ast?: ASTNode) => { @@ -7,13 +7,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!value.trim().length) { - throw createGraphQLError(`Value cannot be an empty string: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value cannot be an empty string: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLNonEmptyString: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLNonEmptyString = /*#__PURE__*/ new GraphQLScalarType({ name: 'NonEmptyString', description: 'A string that cannot be passed as an empty value', diff --git a/src/scalars/NonNegativeFloat.ts b/src/scalars/NonNegativeFloat.ts index d9f4a1ba5..036bcccb8 100644 --- a/src/scalars/NonNegativeFloat.ts +++ b/src/scalars/NonNegativeFloat.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; +import { GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; @@ -19,7 +19,7 @@ export const GraphQLNonNegativeFloatConfig: GraphQLScalarTypeConfig = if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT) { throw createGraphQLError( `Can only validate floating point numbers as non-negative floating point numbers but got a: ${ast.kind}`, - { nodes: ast } + { nodes: ast }, ); } @@ -35,6 +35,6 @@ export const GraphQLNonNegativeFloatConfig: GraphQLScalarTypeConfig = }, }; -export const GraphQLNonNegativeFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( - GraphQLNonNegativeFloatConfig +export const GraphQLNonNegativeFloat = /*#__PURE__*/ new GraphQLScalarType( + GraphQLNonNegativeFloatConfig, ); diff --git a/src/scalars/NonNegativeInt.ts b/src/scalars/NonNegativeInt.ts index fe715ef59..9ad54de0b 100644 --- a/src/scalars/NonNegativeInt.ts +++ b/src/scalars/NonNegativeInt.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; +import { GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; @@ -17,9 +17,12 @@ export const GraphQLNonNegativeIntConfig: GraphQLScalarTypeConfig = /* parseLiteral(ast) { if (ast.kind !== Kind.INT) { - throw createGraphQLError(`Can only validate integers as non-negative integers but got a: ${ast.kind}`, { - nodes: ast, - }); + throw createGraphQLError( + `Can only validate integers as non-negative integers but got a: ${ast.kind}`, + { + nodes: ast, + }, + ); } return processValue(ast.value, 'NonNegativeInt'); @@ -34,6 +37,6 @@ export const GraphQLNonNegativeIntConfig: GraphQLScalarTypeConfig = /* }, }; -export const GraphQLNonNegativeInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( - GraphQLNonNegativeIntConfig +export const GraphQLNonNegativeInt = /*#__PURE__*/ new GraphQLScalarType( + GraphQLNonNegativeIntConfig, ); diff --git a/src/scalars/NonPositiveFloat.ts b/src/scalars/NonPositiveFloat.ts index 0dcae1a83..dc442152c 100644 --- a/src/scalars/NonPositiveFloat.ts +++ b/src/scalars/NonPositiveFloat.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLNonPositiveFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLNonPositiveFloat = /*#__PURE__*/ new GraphQLScalarType({ name: 'NonPositiveFloat', description: 'Floats that will have a value of 0 or less.', @@ -19,7 +19,7 @@ export const GraphQLNonPositiveFloat: GraphQLScalarType = /*#__PURE__*/ new Grap if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT) { throw createGraphQLError( `Can only validate floating point numbers as non-positive floating point numbers but got a: ${ast.kind}`, - { nodes: ast } + { nodes: ast }, ); } diff --git a/src/scalars/NonPositiveInt.ts b/src/scalars/NonPositiveInt.ts index 2fe34065f..3858cdf6b 100644 --- a/src/scalars/NonPositiveInt.ts +++ b/src/scalars/NonPositiveInt.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLNonPositiveInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLNonPositiveInt = /*#__PURE__*/ new GraphQLScalarType({ name: 'NonPositiveInt', description: 'Integers that will have a value of 0 or less.', @@ -17,9 +17,12 @@ export const GraphQLNonPositiveInt: GraphQLScalarType = /*#__PURE__*/ new GraphQ parseLiteral(ast) { if (ast.kind !== Kind.INT) { - throw createGraphQLError(`Can only validate integers as non-positive integers but got a: ${ast.kind}`, { - nodes: ast, - }); + throw createGraphQLError( + `Can only validate integers as non-positive integers but got a: ${ast.kind}`, + { + nodes: ast, + }, + ); } return processValue(ast.value, 'NonPositiveInt'); diff --git a/src/scalars/ObjectID.ts b/src/scalars/ObjectID.ts index 9c33cbd4c..e06c989f8 100644 --- a/src/scalars/ObjectID.ts +++ b/src/scalars/ObjectID.ts @@ -1,9 +1,9 @@ -import { Kind, GraphQLScalarType, ValueNode } from 'graphql'; +import { GraphQLScalarType, Kind, ValueNode } from 'graphql'; import { createGraphQLError } from '../error.js'; const MONGODB_OBJECTID_REGEX = /*#__PURE__*/ /^[A-Fa-f0-9]{24}$/; -export const GraphQLObjectID: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLObjectID = /*#__PURE__*/ new GraphQLScalarType({ name: 'ObjectID', description: @@ -27,13 +27,18 @@ export const GraphQLObjectID: GraphQLScalarType = /*#__PURE__*/ new GraphQLScala parseLiteral(ast: ValueNode) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as mongodb object id but got a: ${ast.kind}`, { - nodes: [ast], - }); + throw createGraphQLError( + `Can only validate strings as mongodb object id but got a: ${ast.kind}`, + { + nodes: [ast], + }, + ); } if (!MONGODB_OBJECTID_REGEX.test(ast.value)) { - throw createGraphQLError(`Value is not a valid mongodb object id of form: ${ast.value}`, { nodes: ast }); + throw createGraphQLError(`Value is not a valid mongodb object id of form: ${ast.value}`, { + nodes: ast, + }); } return ast.value; diff --git a/src/scalars/PhoneNumber.ts b/src/scalars/PhoneNumber.ts index fbcbd005b..711160880 100644 --- a/src/scalars/PhoneNumber.ts +++ b/src/scalars/PhoneNumber.ts @@ -1,9 +1,9 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const PHONE_NUMBER_REGEX = /^\+[1-9]\d{6,14}$/; -export const GraphQLPhoneNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLPhoneNumber = /*#__PURE__*/ new GraphQLScalarType({ name: 'PhoneNumber', description: @@ -15,7 +15,9 @@ export const GraphQLPhoneNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc } if (!PHONE_NUMBER_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid phone number of the form +17895551234 (7-15 digits): ${value}`); + throw createGraphQLError( + `Value is not a valid phone number of the form +17895551234 (7-15 digits): ${value}`, + ); } return value; @@ -27,7 +29,9 @@ export const GraphQLPhoneNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc } if (!PHONE_NUMBER_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid phone number of the form +17895551234 (7-15 digits): ${value}`); + throw createGraphQLError( + `Value is not a valid phone number of the form +17895551234 (7-15 digits): ${value}`, + ); } return value; @@ -35,13 +39,16 @@ export const GraphQLPhoneNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as phone numbers but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as phone numbers but got a: ${ast.kind}`, + { nodes: ast }, + ); } if (!PHONE_NUMBER_REGEX.test(ast.value)) { throw createGraphQLError( `Value is not a valid phone number of the form +17895551234 (7-15 digits): ${ast.value}`, - { nodes: ast } + { nodes: ast }, ); } diff --git a/src/scalars/Port.ts b/src/scalars/Port.ts index 6bb231b70..2fb59b33d 100644 --- a/src/scalars/Port.ts +++ b/src/scalars/Port.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const validate = (value: any, ast?: ASTNode) => { @@ -9,17 +9,23 @@ const validate = (value: any, ast?: ASTNode) => { } if (parsed === Infinity || parsed === -Infinity) { - throw createGraphQLError(`Value is not a finite number: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a finite number: ${value}`, + ast ? { nodes: ast } : undefined, + ); } if (parsed <= 0 || parsed > 65535) { - throw createGraphQLError(`Value is not a valid TCP port: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid TCP port: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return parsed; }; -export const GraphQLPort: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLPort = /*#__PURE__*/ new GraphQLScalarType({ name: `Port`, description: `A field whose value is a valid TCP port within the range of 0 to 65535: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_ports`, @@ -34,7 +40,9 @@ export const GraphQLPort: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.INT) { - throw createGraphQLError(`Can only validate integers as TCP ports but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate integers as TCP ports but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/PositiveFloat.ts b/src/scalars/PositiveFloat.ts index ac212b5cf..e750f2f0f 100644 --- a/src/scalars/PositiveFloat.ts +++ b/src/scalars/PositiveFloat.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLPositiveFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLPositiveFloat = /*#__PURE__*/ new GraphQLScalarType({ name: 'PositiveFloat', description: 'Floats that will have a value greater than 0.', @@ -19,7 +19,7 @@ export const GraphQLPositiveFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQL if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT) { throw createGraphQLError( `Can only validate floating point numbers as positive floating point numbers but got a: ${ast.kind}`, - { nodes: ast } + { nodes: ast }, ); } diff --git a/src/scalars/PositiveInt.ts b/src/scalars/PositiveInt.ts index ed417069d..19f8b2b0c 100644 --- a/src/scalars/PositiveInt.ts +++ b/src/scalars/PositiveInt.ts @@ -1,8 +1,8 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; import { processValue } from './utilities.js'; -export const GraphQLPositiveInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLPositiveInt = /*#__PURE__*/ new GraphQLScalarType({ name: 'PositiveInt', description: 'Integers that will have a value greater than 0.', @@ -17,9 +17,12 @@ export const GraphQLPositiveInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLSc parseLiteral(ast) { if (ast.kind !== Kind.INT) { - throw createGraphQLError(`Can only validate integers as positive integers but got a: ${ast.kind}`, { - nodes: ast, - }); + throw createGraphQLError( + `Can only validate integers as positive integers but got a: ${ast.kind}`, + { + nodes: ast, + }, + ); } return processValue(ast.value, 'PositiveInt'); diff --git a/src/scalars/PostalCode.ts b/src/scalars/PostalCode.ts index be4fb695a..0176cbaaa 100644 --- a/src/scalars/PostalCode.ts +++ b/src/scalars/PostalCode.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; // We're going to start with a limited set as suggested here: @@ -74,7 +74,7 @@ function _testPostalCode(postalCode: string) { return result; } -export const GraphQLPostalCode: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLPostalCode = /*#__PURE__*/ new GraphQLScalarType({ name: 'PostalCode', description: @@ -106,7 +106,9 @@ export const GraphQLPostalCode: GraphQLScalarType = /*#__PURE__*/ new GraphQLSca parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as postal codes but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as postal codes but got a: ${ast.kind}`, { + nodes: ast, + }); } if (!_testPostalCode(ast.value)) { diff --git a/src/scalars/RGB.ts b/src/scalars/RGB.ts index 8f5f9c11a..2196d503c 100644 --- a/src/scalars/RGB.ts +++ b/src/scalars/RGB.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const RGB_REGEX = @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!RGB_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid RGB color: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid RGB color: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLRGB: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLRGB = /*#__PURE__*/ new GraphQLScalarType({ name: `RGB`, description: `A field whose value is a CSS RGB color: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb()_and_rgba().`, @@ -31,7 +34,9 @@ export const GraphQLRGB: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as RGB colors but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as RGB colors but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/RGBA.ts b/src/scalars/RGBA.ts index 53eb0896b..b528e5015 100644 --- a/src/scalars/RGBA.ts +++ b/src/scalars/RGBA.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const RGBA_REGEX = @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!RGBA_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid RGBA color: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid RGBA color: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLRGBA: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLRGBA = /*#__PURE__*/ new GraphQLScalarType({ name: `RGBA`, description: `A field whose value is a CSS RGBA color: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb()_and_rgba().`, @@ -31,7 +34,9 @@ export const GraphQLRGBA: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTyp parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as RGBA colors but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as RGBA colors but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/RoutingNumber.ts b/src/scalars/RoutingNumber.ts index 35d23ff01..7afbc2fa9 100644 --- a/src/scalars/RoutingNumber.ts +++ b/src/scalars/RoutingNumber.ts @@ -75,9 +75,12 @@ export const GraphQLRoutingNumberConfig: GraphQLScalarTypeConfig return validate(ast.value, ast); } - throw createGraphQLError(`ABA Routing Transit Number can only parse Integer or String but got '${ast.kind}'`, { - nodes: ast, - }); + throw createGraphQLError( + `ABA Routing Transit Number can only parse Integer or String but got '${ast.kind}'`, + { + nodes: ast, + }, + ); }, extensions: { codegenScalarType: 'string', @@ -89,4 +92,4 @@ export const GraphQLRoutingNumberConfig: GraphQLScalarTypeConfig }, }; -export const GraphQLRoutingNumber: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLRoutingNumberConfig); +export const GraphQLRoutingNumber = /*#__PURE__*/ new GraphQLScalarType(GraphQLRoutingNumberConfig); diff --git a/src/scalars/SafeInt.ts b/src/scalars/SafeInt.ts index c1f2034c3..f07ab3cbb 100644 --- a/src/scalars/SafeInt.ts +++ b/src/scalars/SafeInt.ts @@ -1,5 +1,4 @@ // Based on https://github.com/stems/graphql-bigint/ - import { GraphQLScalarType, GraphQLScalarTypeConfig, Kind, print } from 'graphql'; import { createGraphQLError } from '../error.js'; import { serializeObject } from './utilities.js'; @@ -46,13 +45,18 @@ export const GraphQLSafeIntConfig = { parseLiteral(valueNode) { if (valueNode.kind !== Kind.INT) { - throw createGraphQLError(`SafeInt cannot represent non-integer value: ${print(valueNode)}`, { nodes: valueNode }); + throw createGraphQLError(`SafeInt cannot represent non-integer value: ${print(valueNode)}`, { + nodes: valueNode, + }); } const num = parseInt(valueNode.value, 10); if (!Number.isSafeInteger(num)) { - throw createGraphQLError(`SafeInt cannot represent unsafe integer value: ${valueNode.value}`, { - nodes: valueNode, - }); + throw createGraphQLError( + `SafeInt cannot represent unsafe integer value: ${valueNode.value}`, + { + nodes: valueNode, + }, + ); } return num; }, @@ -67,4 +71,4 @@ export const GraphQLSafeIntConfig = { }, } as GraphQLScalarTypeConfig; -export const GraphQLSafeInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLSafeIntConfig); +export const GraphQLSafeInt = /*#__PURE__*/ new GraphQLScalarType(GraphQLSafeIntConfig); diff --git a/src/scalars/SemVer.ts b/src/scalars/SemVer.ts index 6f3cf7caf..c63fad355 100644 --- a/src/scalars/SemVer.ts +++ b/src/scalars/SemVer.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const SEMVER_REGEX = @@ -10,13 +10,16 @@ const validate = (value: any, ast?: ASTNode) => { } if (!SEMVER_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid Semantic Version: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid Semantic Version: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLSemVer: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLSemVer = /*#__PURE__*/ new GraphQLScalarType({ name: `SemVer`, description: `A field whose value is a Semantic Version: https://semver.org`, @@ -31,7 +34,10 @@ export const GraphQLSemVer: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarT parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as Semantic Version but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as Semantic Version but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); diff --git a/src/scalars/TimeZone.ts b/src/scalars/TimeZone.ts index ed81d7749..a42a8aba1 100644 --- a/src/scalars/TimeZone.ts +++ b/src/scalars/TimeZone.ts @@ -9,7 +9,7 @@ const validateTimeZone = (str: string, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } @@ -24,7 +24,7 @@ const validateTimeZone = (str: string, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } else { throw createGraphQLError( @@ -33,16 +33,17 @@ const validateTimeZone = (str: string, ast?: ValueNode) => { ? { nodes: ast, } - : undefined + : undefined, ); } } }; -export const GraphQLTimeZone: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLTimeZone = /*#__PURE__*/ new GraphQLScalarType({ name: 'TimeZone', - description: 'A field whose value exists in the standard IANA Time Zone Database: https://www.iana.org/time-zones', + description: + 'A field whose value exists in the standard IANA Time Zone Database: https://www.iana.org/time-zones', serialize: validateTimeZone, diff --git a/src/scalars/Timestamp.ts b/src/scalars/Timestamp.ts index 2811c89a0..910c171e5 100644 --- a/src/scalars/Timestamp.ts +++ b/src/scalars/Timestamp.ts @@ -35,7 +35,7 @@ function parseDateFromLiteral(ast: ValueNode) { return null; } -export const GraphQLTimestamp: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLTimestamp = /*#__PURE__*/ new GraphQLScalarType({ name: 'Timestamp', description: 'The javascript `Date` as integer. Type represents date and time ' + diff --git a/src/scalars/URL.ts b/src/scalars/URL.ts index 1aa57d118..a1394e8ab 100644 --- a/src/scalars/URL.ts +++ b/src/scalars/URL.ts @@ -1,7 +1,7 @@ -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; -export const GraphQLURL: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLURL = /*#__PURE__*/ new GraphQLScalarType({ name: 'URL', description: @@ -19,7 +19,9 @@ export const GraphQLURL: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as URLs but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as URLs but got a: ${ast.kind}`, { + nodes: ast, + }); } if (ast.value === null) { diff --git a/src/scalars/USCurrency.ts b/src/scalars/USCurrency.ts index 47f6e0e71..014ec767d 100644 --- a/src/scalars/USCurrency.ts +++ b/src/scalars/USCurrency.ts @@ -1,5 +1,5 @@ // https://github.com/abhiaiyer91/graphql-currency-scalars -import { Kind, GraphQLScalarType } from 'graphql'; +import { GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; function generateCurrency(value: any) { @@ -33,13 +33,15 @@ function generateCents(value: string) { * currency strings. */ -export const GraphQLUSCurrency: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLUSCurrency = /*#__PURE__*/ new GraphQLScalarType({ name: 'USCurrency', description: 'A currency string, such as $21.25', serialize: generateCurrency, parseValue(value) { if (typeof value !== 'string') { - throw createGraphQLError(`Currency cannot represent non string type ${JSON.stringify(value)}`); + throw createGraphQLError( + `Currency cannot represent non string type ${JSON.stringify(value)}`, + ); } return generateCents(value); @@ -50,9 +52,12 @@ export const GraphQLUSCurrency: GraphQLScalarType = /*#__PURE__*/ new GraphQLSca return generateCents(ast.value); } } - throw createGraphQLError(`Currency cannot represent an invalid currency-string ${JSON.stringify(ast)}.`, { - nodes: ast, - }); + throw createGraphQLError( + `Currency cannot represent an invalid currency-string ${JSON.stringify(ast)}.`, + { + nodes: ast, + }, + ); }, extensions: { codegenScalarType: 'string', diff --git a/src/scalars/UUID.ts b/src/scalars/UUID.ts index 09ef1983f..e53907c63 100644 --- a/src/scalars/UUID.ts +++ b/src/scalars/UUID.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const validate = (value: any, ast?: ASTNode) => { @@ -14,7 +14,10 @@ const validate = (value: any, ast?: ASTNode) => { } if (!UUID_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid UUID: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid UUID: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; @@ -35,7 +38,9 @@ export const GraphQLUUIDConfig: GraphQLScalarTypeConfig = /*#__P parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as UUIDs but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as UUIDs but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); @@ -49,4 +54,4 @@ export const GraphQLUUIDConfig: GraphQLScalarTypeConfig = /*#__P }, }; -export const GraphQLUUID: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLUUIDConfig); +export const GraphQLUUID = /*#__PURE__*/ new GraphQLScalarType(GraphQLUUIDConfig); diff --git a/src/scalars/UnsignedFloat.ts b/src/scalars/UnsignedFloat.ts index aeed17845..d590c514d 100644 --- a/src/scalars/UnsignedFloat.ts +++ b/src/scalars/UnsignedFloat.ts @@ -5,4 +5,4 @@ const GraphQLUnsignedFloatConfig = /*#__PURE__*/ Object.assign({}, GraphQLNonNeg name: 'UnsignedFloat', }); -export const GraphQLUnsignedFloat: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLUnsignedFloatConfig); +export const GraphQLUnsignedFloat = /*#__PURE__*/ new GraphQLScalarType(GraphQLUnsignedFloatConfig); diff --git a/src/scalars/UnsignedInt.ts b/src/scalars/UnsignedInt.ts index e9de8f882..b82c64569 100644 --- a/src/scalars/UnsignedInt.ts +++ b/src/scalars/UnsignedInt.ts @@ -5,4 +5,4 @@ const GraphQLUnsignedIntConfig = /*#__PURE__*/ Object.assign({}, GraphQLNonNegat name: 'UnsignedInt', }); -export const GraphQLUnsignedInt: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLUnsignedIntConfig); +export const GraphQLUnsignedInt = /*#__PURE__*/ new GraphQLScalarType(GraphQLUnsignedIntConfig); diff --git a/src/scalars/UtcOffset.ts b/src/scalars/UtcOffset.ts index 6737539b2..ea84467fa 100644 --- a/src/scalars/UtcOffset.ts +++ b/src/scalars/UtcOffset.ts @@ -1,4 +1,4 @@ -import { Kind, GraphQLScalarType, ASTNode } from 'graphql'; +import { ASTNode, GraphQLScalarType, Kind } from 'graphql'; import { createGraphQLError } from '../error.js'; const UTC_OFFSET_REGEX = /^([+-]?)(\d{2}):(\d{2})$/; @@ -8,16 +8,20 @@ const validate = (value: any, ast?: ASTNode) => { } if (!UTC_OFFSET_REGEX.test(value)) { - throw createGraphQLError(`Value is not a valid UTC Offset: ${value}`, ast ? { nodes: ast } : undefined); + throw createGraphQLError( + `Value is not a valid UTC Offset: ${value}`, + ast ? { nodes: ast } : undefined, + ); } return value; }; -export const GraphQLUtcOffset: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLUtcOffset = /*#__PURE__*/ new GraphQLScalarType({ name: 'UtcOffset', - description: 'A field whose value is a UTC Offset: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones', + description: + 'A field whose value is a UTC Offset: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones', serialize: validate, @@ -25,7 +29,9 @@ export const GraphQLUtcOffset: GraphQLScalarType = /*#__PURE__*/ new GraphQLScal parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as UTC Offset but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as UTC Offset but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); diff --git a/src/scalars/Void.ts b/src/scalars/Void.ts index 1f4371cff..6a9a5a079 100644 --- a/src/scalars/Void.ts +++ b/src/scalars/Void.ts @@ -1,6 +1,6 @@ import { GraphQLScalarType } from 'graphql'; -export const GraphQLVoid: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLVoid = /*#__PURE__*/ new GraphQLScalarType({ name: 'Void', description: 'Represents NULL values', diff --git a/src/scalars/iso-date/Date.ts b/src/scalars/iso-date/Date.ts index 3093c4ac7..f80f8a928 100644 --- a/src/scalars/iso-date/Date.ts +++ b/src/scalars/iso-date/Date.ts @@ -6,12 +6,11 @@ * LICENSE file in the root directory of this source tree. * */ - import { GraphQLScalarType, Kind } from 'graphql'; import type { GraphQLScalarTypeConfig } from 'graphql'; -import { validateJSDate, validateDate } from './validator.js'; -import { serializeDate, parseDate } from './formatter.js'; import { createGraphQLError } from '../../error.js'; +import { parseDate, serializeDate } from './formatter.js'; +import { validateDate, validateJSDate } from './validator.js'; export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PURE__*/ { name: 'Date', @@ -32,7 +31,9 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR } throw createGraphQLError(`Date cannot represent an invalid date-string ${value}.`); } else { - throw createGraphQLError('Date cannot represent a non string, or non Date type ' + JSON.stringify(value)); + throw createGraphQLError( + 'Date cannot represent a non string, or non Date type ' + JSON.stringify(value), + ); } }, parseValue(value) { @@ -47,13 +48,18 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR }, parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Date cannot represent non string type ${'value' in ast && ast.value}`, { nodes: ast }); + throw createGraphQLError( + `Date cannot represent non string type ${'value' in ast && ast.value}`, + { nodes: ast }, + ); } const { value } = ast; if (validateDate(value)) { return parseDate(value); } - throw createGraphQLError(`Date cannot represent an invalid date-string ${String(value)}.`, { nodes: ast }); + throw createGraphQLError(`Date cannot represent an invalid date-string ${String(value)}.`, { + nodes: ast, + }); }, extensions: { codegenScalarType: 'Date | string', @@ -75,4 +81,4 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR * This scalar serializes javascript Dates and * RFC 3339 date strings to RFC 3339 date strings. */ -export const GraphQLDate: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLDateConfig); +export const GraphQLDate = /*#__PURE__*/ new GraphQLScalarType(GraphQLDateConfig); diff --git a/src/scalars/iso-date/DateTime.ts b/src/scalars/iso-date/DateTime.ts index 83ae0c5cc..2779df420 100644 --- a/src/scalars/iso-date/DateTime.ts +++ b/src/scalars/iso-date/DateTime.ts @@ -6,12 +6,12 @@ * LICENSE file in the root directory of this source tree. * */ - import { GraphQLScalarType, Kind } from 'graphql'; -import type { GraphQLScalarTypeConfig } from 'graphql'; // eslint-disable-line -import { validateJSDate, validateDateTime } from './validator.js'; -import { parseDateTime } from './formatter.js'; +import type { GraphQLScalarTypeConfig } from 'graphql'; import { createGraphQLError } from '../../error.js'; +import { parseDateTime } from './formatter.js'; +// eslint-disable-line +import { validateDateTime, validateJSDate } from './validator.js'; export const GraphQLDateTimeConfig: GraphQLScalarTypeConfig = /*#__PURE__*/ { name: 'DateTime', @@ -39,7 +39,9 @@ export const GraphQLDateTimeConfig: GraphQLScalarTypeConfig = /*#__P } } else { throw createGraphQLError( - 'DateTime cannot be serialized from a non string, ' + 'non numeric or non Date type ' + JSON.stringify(value) + 'DateTime cannot be serialized from a non string, ' + + 'non numeric or non Date type ' + + JSON.stringify(value), ); } }, @@ -56,19 +58,27 @@ export const GraphQLDateTimeConfig: GraphQLScalarTypeConfig = /*#__P } throw createGraphQLError(`DateTime cannot represent an invalid date-time-string ${value}.`); } - throw createGraphQLError(`DateTime cannot represent non string or Date type ${JSON.stringify(value)}`); + throw createGraphQLError( + `DateTime cannot represent non string or Date type ${JSON.stringify(value)}`, + ); }, parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`DateTime cannot represent non string or Date type ${'value' in ast && ast.value}`, { - nodes: ast, - }); + throw createGraphQLError( + `DateTime cannot represent non string or Date type ${'value' in ast && ast.value}`, + { + nodes: ast, + }, + ); } const { value } = ast; if (validateDateTime(value)) { return parseDateTime(value); } - throw createGraphQLError(`DateTime cannot represent an invalid date-time-string ${String(value)}.`, { nodes: ast }); + throw createGraphQLError( + `DateTime cannot represent an invalid date-time-string ${String(value)}.`, + { nodes: ast }, + ); }, extensions: { codegenScalarType: 'Date | string', @@ -91,4 +101,4 @@ export const GraphQLDateTimeConfig: GraphQLScalarTypeConfig = /*#__P * RFC 3339 date-time strings and unix timestamps * to RFC 3339 UTC date-time strings. */ -export const GraphQLDateTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLDateTimeConfig); +export const GraphQLDateTime = /*#__PURE__*/ new GraphQLScalarType(GraphQLDateTimeConfig); diff --git a/src/scalars/iso-date/Duration.ts b/src/scalars/iso-date/Duration.ts index 7bad89636..5032f43aa 100644 --- a/src/scalars/iso-date/Duration.ts +++ b/src/scalars/iso-date/Duration.ts @@ -59,7 +59,10 @@ export const GraphQLDurationConfig: GraphQLScalarTypeConfig = /* parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as ISO Durations but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as ISO Durations but got a: ${ast.kind}`, + { nodes: ast }, + ); } if (!ISO_DURATION.test(ast.value)) { throw createGraphQLError(`Value is not a valid ISO Duration: ${ast.value}`, { nodes: ast }); @@ -77,12 +80,12 @@ export const GraphQLDurationConfig: GraphQLScalarTypeConfig = /* }, }; -export const GraphQLISO8601Duration: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLISO8601Duration = /*#__PURE__*/ new GraphQLScalarType({ ...GraphQLDurationConfig, name: 'ISO8601Duration', }); -export const GraphQLDuration: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType({ +export const GraphQLDuration = /*#__PURE__*/ new GraphQLScalarType({ ...GraphQLDurationConfig, name: 'Duration', }); diff --git a/src/scalars/iso-date/Time.ts b/src/scalars/iso-date/Time.ts index 9999862a0..8fd5e8ee5 100644 --- a/src/scalars/iso-date/Time.ts +++ b/src/scalars/iso-date/Time.ts @@ -6,12 +6,12 @@ * LICENSE file in the root directory of this source tree. * */ - import { GraphQLScalarType, Kind } from 'graphql'; -import type { GraphQLScalarTypeConfig } from 'graphql'; // eslint-disable-line -import { validateJSDate, validateTime } from './validator.js'; -import { serializeTime, serializeTimeString, parseTime } from './formatter.js'; +import type { GraphQLScalarTypeConfig } from 'graphql'; import { createGraphQLError } from '../../error.js'; +import { parseTime, serializeTime, serializeTimeString } from './formatter.js'; +// eslint-disable-line +import { validateJSDate, validateTime } from './validator.js'; /** * An RFC 3339 compliant time scalar. @@ -45,7 +45,9 @@ const config: GraphQLScalarTypeConfig = { throw createGraphQLError(`Time cannot represent an invalid time-string ${value}.`); } else { throw createGraphQLError( - 'Time cannot be serialized from a non string, ' + 'or non Date type ' + JSON.stringify(value) + 'Time cannot be serialized from a non string, ' + + 'or non Date type ' + + JSON.stringify(value), ); } }, @@ -61,13 +63,18 @@ const config: GraphQLScalarTypeConfig = { }, parseLiteral(ast): Date { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Time cannot represent non string type ${'value' in ast && ast.value}`, { nodes: ast }); + throw createGraphQLError( + `Time cannot represent non string type ${'value' in ast && ast.value}`, + { nodes: ast }, + ); } const value = ast.value; if (validateTime(value)) { return parseTime(value); } - throw createGraphQLError(`Time cannot represent an invalid time-string ${String(value)}.`, { nodes: ast }); + throw createGraphQLError(`Time cannot represent an invalid time-string ${String(value)}.`, { + nodes: ast, + }); }, extensions: { codegenScalarType: 'Date | string', @@ -78,4 +85,4 @@ const config: GraphQLScalarTypeConfig = { }, }; -export const GraphQLTime: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(config); +export const GraphQLTime = /*#__PURE__*/ new GraphQLScalarType(config); diff --git a/src/scalars/json/JSON.ts b/src/scalars/json/JSON.ts index f41acf658..ef386d857 100644 --- a/src/scalars/json/JSON.ts +++ b/src/scalars/json/JSON.ts @@ -1,5 +1,4 @@ // This named export is intended for users of CommonJS. Users of ES modules - import { GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; import { identity, parseLiteral } from './utils.js'; @@ -19,4 +18,4 @@ export const GraphQLJSONConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLJSON: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLJSONConfig); +export const GraphQLJSON = /*#__PURE__*/ new GraphQLScalarType(GraphQLJSONConfig); diff --git a/src/scalars/json/JSONObject.ts b/src/scalars/json/JSONObject.ts index d5d01f1e5..91e36baf0 100644 --- a/src/scalars/json/JSONObject.ts +++ b/src/scalars/json/JSONObject.ts @@ -22,4 +22,4 @@ export const GraphQLJSONObjectConfig = /*#__PURE__*/ { }, } as GraphQLScalarTypeConfig; -export const GraphQLJSONObject: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLJSONObjectConfig); +export const GraphQLJSONObject = /*#__PURE__*/ new GraphQLScalarType(GraphQLJSONObjectConfig); diff --git a/src/scalars/library/DeweyDecimal.ts b/src/scalars/library/DeweyDecimal.ts index 2019afe2e..bdd9bb64d 100644 --- a/src/scalars/library/DeweyDecimal.ts +++ b/src/scalars/library/DeweyDecimal.ts @@ -1,4 +1,4 @@ -import { GraphQLScalarTypeConfig, ASTNode, Kind, GraphQLScalarType } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../../error.js'; const DEWEY_DECIMAL_REGEX = /^[0-9]{1,3}(?:\.[0-9]+)?$/; @@ -14,7 +14,8 @@ const validate = (value: any, ast?: ASTNode) => { return value; }; -const specifiedByURL = 'https://www.oclc.org/content/dam/oclc/dewey/resources/summaries/deweysummaries.pdf'; +const specifiedByURL = + 'https://www.oclc.org/content/dam/oclc/dewey/resources/summaries/deweysummaries.pdf'; export const GraphQLDeweyDecimalConfig = { name: 'DeweyDecimal', @@ -27,7 +28,9 @@ export const GraphQLDeweyDecimalConfig = { parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as DeweyDecimal but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError(`Can only validate strings as DeweyDecimal but got a: ${ast.kind}`, { + nodes: ast, + }); } return validate(ast.value, ast); @@ -45,4 +48,4 @@ export const GraphQLDeweyDecimalConfig = { }, } as GraphQLScalarTypeConfig; -export const GraphQLDeweyDecimal: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLDeweyDecimalConfig); +export const GraphQLDeweyDecimal = /*#__PURE__*/ new GraphQLScalarType(GraphQLDeweyDecimalConfig); diff --git a/src/scalars/library/LCCSubclass.ts b/src/scalars/library/LCCSubclass.ts index cace1ffab..264c66768 100644 --- a/src/scalars/library/LCCSubclass.ts +++ b/src/scalars/library/LCCSubclass.ts @@ -1,4 +1,4 @@ -import { GraphQLScalarType, GraphQLScalarTypeConfig, ASTNode, Kind } from 'graphql'; +import { ASTNode, GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql'; import { createGraphQLError } from '../../error.js'; //Regex for the various letter subclasses of the Library of Congress Classification @@ -31,7 +31,10 @@ export const GraphQLLCCSubclassConfig = { parseLiteral(ast) { if (ast.kind !== Kind.STRING) { - throw createGraphQLError(`Can only validate strings as LCC Subclasses but got a: ${ast.kind}`, { nodes: ast }); + throw createGraphQLError( + `Can only validate strings as LCC Subclasses but got a: ${ast.kind}`, + { nodes: ast }, + ); } return validate(ast.value, ast); @@ -49,4 +52,4 @@ export const GraphQLLCCSubclassConfig = { }, } as GraphQLScalarTypeConfig; -export const GraphQLLCCSubclass: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType(GraphQLLCCSubclassConfig); +export const GraphQLLCCSubclass = /*#__PURE__*/ new GraphQLScalarType(GraphQLLCCSubclassConfig); diff --git a/src/scalars/patent/IPCPatent.ts b/src/scalars/patent/IPCPatent.ts index 2d9771125..2566eaac3 100644 --- a/src/scalars/patent/IPCPatent.ts +++ b/src/scalars/patent/IPCPatent.ts @@ -57,6 +57,4 @@ export const GraphQLIPCPatentConfig = { }, } as GraphQLScalarTypeConfig; -export const GraphQLIPCPatent: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarType( - GraphQLIPCPatentConfig, -); +export const GraphQLIPCPatent = /*#__PURE__*/ new GraphQLScalarType(GraphQLIPCPatentConfig);