import { FieldKind, FieldNullability, FieldOptionsFromKind, SchemaTypes, TypeParam, } from '../types'; import BaseFieldUtil from './base'; import InputFieldBuilder from './input'; import { ArgBuilder, InputFieldMap, NormalizeArgs } from '..'; export default class RootFieldBuilder< Types extends SchemaTypes, ParentShape, Kind extends FieldKind = FieldKind, > extends BaseFieldUtil { arg: ArgBuilder = new InputFieldBuilder( this.builder, 'Arg', this.typename, ).argBuilder(); /** * Create a Boolean field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ boolean< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<'Boolean'> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, 'Boolean', Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: 'Boolean', }); } /** * Create a Float field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ float< Args extends InputFieldMap, Nullable extends FieldNullability<'Float'>, ResolveShape, ResolveReturnShape, >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, 'Float', Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: 'Float', }); } /** * Create a ID field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ id< Args extends InputFieldMap, Nullable extends FieldNullability<'ID'>, ResolveShape, ResolveReturnShape, >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, 'ID', Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: 'ID' }); } /** * Create a Int field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ int< Args extends InputFieldMap, Nullable extends FieldNullability<'Int'>, ResolveShape, ResolveReturnShape, >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, 'Int', Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: 'Int' }); } /** * Create a String field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ string< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<'String'> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, 'String', Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: 'String', }); } /** * Create a Boolean list field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ booleanList< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<['Boolean']> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, ['Boolean'], Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: ['Boolean'] }); } /** * Create a Float list field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ floatList< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<['Float']> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, ['Float'], Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: ['Float'] }); } /** * Create a ID list field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ idList< Args extends InputFieldMap, Nullable extends FieldNullability<['ID']>, ResolveShape, ResolveReturnShape, >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, ['ID'], Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: ['ID'] }); } /** * Create a Int list field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ intList< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<['Int']> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, ['Int'], Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: ['Int'] }); } /** * Create a String list field * @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field */ stringList< Args extends InputFieldMap, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability<['String']> = Types['DefaultFieldNullability'], >( ...args: NormalizeArgs< [ options?: Omit< FieldOptionsFromKind< Types, ParentShape, ['String'], Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, 'type' >, ] > ) { const [options = {} as never] = args; return this.createField({ ...options, type: ['String'] }); } /** * create a new field for the current type * @param {GiraphQLSchemaTypes.FieldOptions} options - options for this field */ field< Args extends InputFieldMap, Type extends TypeParam, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability = Types['DefaultFieldNullability'], >( options: FieldOptionsFromKind< Types, ParentShape, Type, Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, ) { return this.createField(options); } }