UNPKG

@graphql-codegen/typescript-operations

Version:

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

27 lines (26 loc) 862 B
import { TypeScriptOperationVariablesToObject as TSOperationVariablesToObject } from '@graphql-codegen/typescript'; const SCALARS = { ID: 'string | number', String: 'string', Int: 'number', Float: 'number', Boolean: 'boolean', }; const MAYBE_SUFFIX = ' | null'; export class TypeScriptOperationVariablesToObject extends TSOperationVariablesToObject { 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'; } }