import type { Tagged } from 'type-fest'; /** 表示 GQL 类型的字符串 */ export type GqlType = Tagged; /** 校验 GQL 类型 */ export function formatType(type: T, simpleTypeOnly: boolean): GqlType { if (!type || typeof type != 'string') throw new TypeError('type must be a string'); type = type.replaceAll(/\s+/g, '') as T; if (!type) throw new Error('type must not be empty'); if (simpleTypeOnly) { if (type.includes('[')) throw new Error('type must not contain array'); if (type.includes('!')) throw new Error('type must not contain non-null assertion'); } return type as GqlType; }