INNER CODE UNIT · TypeScript

isOptional

stepci/garph · src/schema.ts:23

function isOptional(target: string, type: AnyType, config: ConverterConfig) {
  return type.typeDef.isRequired ? `${target}!` : type.typeDef.isOptional ? `${target}` : config.defaultNullability ? `${target}` : `${target}!`
}

export function getFieldType(schemaComposer: SchemaComposer, type: AnyType, config: ConverterConfig) {
  switch (type.typeDef.type) {
    case 'String':
      return isOptional('String', type, config)
    case 'Int':
      return isOptional('Int', type, config)
    case 'Float':
      return isOptional('Float', type, config)
    case 'Boolean':
      return isOptional('Boolean', type, config)
    case 'ID':
      return isOptional('ID', type, config)
    case 'List':
      return isOptional(`[${getFieldType(schemaComposer, type.typeDef.shape, config)}]`, type, config)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…