Skip to content

Commit

Permalink
let codegen handle scalar types automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Oct 13, 2021
1 parent c3e6fe2 commit b217d0d
Show file tree
Hide file tree
Showing 46 changed files with 489 additions and 341 deletions.
3 changes: 3 additions & 0 deletions src/RegularExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class RegularExpression extends GraphQLScalarType {

return ast.value;
},
extensions: {
codegenScalarType: 'string',
},
});
}
}
3 changes: 3 additions & 0 deletions src/scalars/BigInt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const GraphQLBigIntConfig: GraphQLScalarTypeConfig<
}
return null;
},
extensions: {
codegenScalarType: 'bigint',
},
};

export const GraphQLBigInt = /*#__PURE__*/ new GraphQLScalarType(
Expand Down
3 changes: 3 additions & 0 deletions src/scalars/Byte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const GraphQLByteConfig: GraphQLScalarTypeConfig<
);
}
},
extensions: {
codegenScalarType: 'Buffer | string',
},
};

export const GraphQLByte = /*#__PURE__*/ new GraphQLScalarType(
Expand Down
48 changes: 25 additions & 23 deletions src/scalars/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
} from 'graphql';

const validate = (value: any) => {
const CURRENCY_REGEX = /^(AED|AFN|ALL|AMD|ANG|AOA|ARS|AUD|AWG|AZN|BAM|BBD|BDT|BGN|BHD|BIF|BMD|BND|BOB|BOV|BRL|BSD|BTN|BWP|BYN|BZD|CAD|CDF|CHE|CHF|CHW|CLF|CLP|CNY|COP|COU|CRC|CUC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HRK|HTG|HUF|IDR|ILS|INR|IQD|IRR|ISK|JMD|JOD|JPY|KES|KGS|KHR|KMF|KPW|KRW|KWD|KYD|KZT|L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XAG|XAU|XBA|XBB|XBC|XBD|XCD|XDR|XOF|XPD|XPF|XPT|XSU|XTS|XUA|XXX|YER|ZAR|ZMW|ZWL)$/i;

if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
Expand All @@ -19,34 +20,35 @@ const validate = (value: any) => {
return value;
};

export const GraphQLCurrencyConfig: GraphQLScalarTypeConfig<
string,
string
> = /*#__PURE__*/ {
name: `Currency`,
export const GraphQLCurrencyConfig: GraphQLScalarTypeConfig<string, string> =
/*#__PURE__*/ {
name: `Currency`,

description: `A field whose value is a Currency: https://en.wikipedia.org/wiki/ISO_4217.`,
description: `A field whose value is a Currency: https://en.wikipedia.org/wiki/ISO_4217.`,

serialize(value) {
return validate(value);
},
serialize(value) {
return validate(value);
},

parseValue(value) {
return validate(value);
},
parseValue(value) {
return validate(value);
},

parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as a currency but got a: ${ast.kind}`,
);
}
parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as a currency but got a: ${ast.kind}`,
);
}

return validate(ast.value);
},
return validate(ast.value);
},

specifiedByUrl: 'https://en.wikipedia.org/wiki/ISO_4217',
};
specifiedByUrl: 'https://en.wikipedia.org/wiki/ISO_4217',
extensions: {
codegenScalarType: 'string',
},
};

export const GraphQLCurrency = /*#__PURE__*/ new GraphQLScalarType(
GraphQLCurrencyConfig,
Expand Down
6 changes: 5 additions & 1 deletion src/scalars/EmailAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
} from 'graphql';

const validate = (value: any) => {
const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const EMAIL_ADDRESS_REGEX =
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;

if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
Expand Down Expand Up @@ -43,6 +44,9 @@ export const GraphQLEmailAddressConfig: GraphQLScalarTypeConfig<
},

specifiedByUrl: 'https://www.w3.org/Protocols/rfc822/',
extensions: {
codegenScalarType: 'string',
},
};

export const GraphQLEmailAddress = /*#__PURE__*/ new GraphQLScalarType(
Expand Down
50 changes: 26 additions & 24 deletions src/scalars/HSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
} from 'graphql';

const validate = (value: any) => {
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*\)$/;

if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
Expand All @@ -19,34 +20,35 @@ const validate = (value: any) => {
return value;
};

export const GraphQLHSLConfig: GraphQLScalarTypeConfig<
string,
string
> = /*#__PURE__*/ {
name: `HSL`,
export const GraphQLHSLConfig: GraphQLScalarTypeConfig<string, string> =
/*#__PURE__*/ {
name: `HSL`,

description: `A field whose value is a CSS HSL color: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla().`,
description: `A field whose value is a CSS HSL color: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla().`,

serialize(value) {
return validate(value);
},
serialize(value) {
return validate(value);
},

parseValue(value) {
return validate(value);
},
parseValue(value) {
return validate(value);
},

parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as HSL colors but got a: ${ast.kind}`,
);
}
parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as HSL colors but got a: ${ast.kind}`,
);
}

return validate(ast.value);
},
return validate(ast.value);
},

specifiedByUrl:
'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla()',
};
specifiedByUrl:
'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#hsl()_and_hsla()',
extensions: {
codegenScalarType: 'string',
},
};

export const GraphQLHSL = /*#__PURE__*/ new GraphQLScalarType(GraphQLHSLConfig);
6 changes: 5 additions & 1 deletion src/scalars/HSLA.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Kind, GraphQLError, GraphQLScalarType } from 'graphql';

const HSLA_REGEX = /^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/;
const HSLA_REGEX =
/^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/;

const validate = (value: any) => {
if (typeof value !== 'string') {
Expand Down Expand Up @@ -36,4 +37,7 @@ export const GraphQLHSLA = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
3 changes: 3 additions & 0 deletions src/scalars/HexColorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const GraphQLHexColorCodeConfig: GraphQLScalarTypeConfig<
},

specifiedByUrl: 'https://en.wikipedia.org/wiki/Web_colors',
extensions: {
codegenScalarType: 'string',
},
};

export const GraphQLHexColorCode = /*#__PURE__*/ new GraphQLScalarType(
Expand Down
53 changes: 27 additions & 26 deletions src/scalars/Hexadecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,33 @@ const validate = (value: string) => {
return value;
};

export const GraphQLHexadecimalConfig: GraphQLScalarTypeConfig<
string,
string
> = /*#__PURE__*/ {
name: `Hexadecimal`,

description: `A field whose value is a hexadecimal: https://en.wikipedia.org/wiki/Hexadecimal.`,

serialize(value) {
return validate(value);
},

parseValue(value) {
return validate(value);
},

parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as a hexadecimal but got a: ${ast.kind}`,
);
}

return validate(ast.value);
},
};
export const GraphQLHexadecimalConfig: GraphQLScalarTypeConfig<string, string> =
/*#__PURE__*/ {
name: `Hexadecimal`,

description: `A field whose value is a hexadecimal: https://en.wikipedia.org/wiki/Hexadecimal.`,

serialize(value) {
return validate(value);
},

parseValue(value) {
return validate(value);
},

parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as a hexadecimal but got a: ${ast.kind}`,
);
}

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
};

export const GraphQLHexadecimal = /*#__PURE__*/ new GraphQLScalarType(
GraphQLHexadecimalConfig,
Expand Down
7 changes: 5 additions & 2 deletions src/scalars/IBAN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function _testIBAN(

function validate(iban: string): boolean {
// Make uppercase and remove whitespace for matching
iban = iban.toUpperCase().replace(/\s+/g, '')
iban = iban.toUpperCase().replace(/\s+/g, '');
const countryCode = iban.slice(0, 2);
const countryStructure = IBAN_SPECIFICATIONS[countryCode];
return !!countryStructure && _testIBAN(iban, countryCode, countryStructure);
Expand Down Expand Up @@ -418,7 +418,7 @@ export const GraphQLIBAN = /*#__PURE__*/ new GraphQLScalarType({
return value;
},

parseLiteral(ast: { kind: any; value: string; }) {
parseLiteral(ast: { kind: any; value: string }) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(
`Can only validate strings as IBANs but got a: ${ast.kind}`,
Expand All @@ -431,4 +431,7 @@ export const GraphQLIBAN = /*#__PURE__*/ new GraphQLScalarType({

return ast.value;
},
extensions: {
codegenScalarType: 'string',
},
});
6 changes: 5 additions & 1 deletion src/scalars/IPv4.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Kind, GraphQLError, GraphQLScalarType } from 'graphql';

const IPV4_REGEX = /^(?:(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?)$/;
const IPV4_REGEX =
/^(?:(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?)$/;

const validate = (value: any) => {
if (typeof value !== 'string') {
Expand Down Expand Up @@ -36,4 +37,7 @@ export const GraphQLIPv4 = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
6 changes: 5 additions & 1 deletion src/scalars/IPv6.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Kind, GraphQLError, GraphQLScalarType } from 'graphql';

const IPV6_REGEX = /^(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9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1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)(?:\/(?:0?0?[0-9]|0?[1-9][0-9]|1[01][0-9]|12[0-8]))?)$/;
const validate = (value: any) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
Expand Down Expand Up @@ -35,4 +36,7 @@ export const GraphQLIPv6 = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
3 changes: 3 additions & 0 deletions src/scalars/ISBN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ export const GraphQLISBN = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
23 changes: 13 additions & 10 deletions src/scalars/JWT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
const JWS_REGEX = /^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;

const validate = (value: any) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
}
if (!JWS_REGEX.test(value)) {
throw new TypeError(`Value is not a valid JWT: ${value}`);
}
return value;
};
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
}

if (!JWS_REGEX.test(value)) {
throw new TypeError(`Value is not a valid JWT: ${value}`);
}

return value;
};

export const GraphQLJWT = /*#__PURE__*/ new GraphQLScalarType({
name: `JWT`,
Expand All @@ -37,4 +37,7 @@ export const GraphQLJWT = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
3 changes: 3 additions & 0 deletions src/scalars/Latitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ export const GraphQLLatitude = /*#__PURE__*/ new GraphQLScalarType({

return validate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});
3 changes: 3 additions & 0 deletions src/scalars/LocalDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ export const GraphQLLocalDate = /*#__PURE__*/ new GraphQLScalarType({

return validateLocalDate(ast.value);
},
extensions: {
codegenScalarType: 'string',
},
});

1 comment on commit b217d0d

@mmahalwy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ardatan how does this work with codegen for the frontend?

Please sign in to comment.