UNPKG

@graphql-codegen/typescript-operations

Version:

GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments

31 lines (30 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeScriptOperationVariablesToObject = void 0; const typescript_1 = require("@graphql-codegen/typescript"); const SCALARS = { ID: 'string | number', String: 'string', Int: 'number', Float: 'number', Boolean: 'boolean', }; const MAYBE_SUFFIX = ' | null'; class TypeScriptOperationVariablesToObject extends typescript_1.TypeScriptOperationVariablesToObject { formatTypeString(fieldType, _isNonNullType, _hasDefaultValue) { return fieldType; } clearOptional(str) { if (str?.endsWith(MAYBE_SUFFIX)) { return (str = str.substring(0, str.length - MAYBE_SUFFIX.length)); } return str; } wrapMaybe(type) { return type?.endsWith(MAYBE_SUFFIX) ? type : `${type}${MAYBE_SUFFIX}`; } getScalar(name) { return this._scalars?.[name]?.input ?? SCALARS[name] ?? 'any'; } } exports.TypeScriptOperationVariablesToObject = TypeScriptOperationVariablesToObject;