import { type FieldRequiredness, InputFieldBuilder, type ObjectRef, type SchemaTypes, } from '@pothos/core'; import type { GlobalIDInputFieldOptions, GlobalIDListInputFieldOptions } from './types.js'; type DefaultSchemaTypes = PothosSchemaTypes.ExtendDefaultTypes<{}>; const inputFieldBuilder = InputFieldBuilder.prototype as PothosSchemaTypes.InputFieldBuilder< DefaultSchemaTypes, 'Arg' | 'InputObject' >; inputFieldBuilder.globalIDList = function globalIDList>( { for: forTypes, ...options }: GlobalIDListInputFieldOptions = {} as never, ) { return this.idList({ ...options, extensions: { ...options.extensions, isRelayGlobalID: true, relayGlobalIDFor: ( (forTypes && (Array.isArray(forTypes) ? forTypes : [forTypes])) as ObjectRef< SchemaTypes, unknown >[] )?.map((type: ObjectRef) => ({ typename: this.builder.configStore.getTypeConfig(type).name, parseId: 'parseId' in type ? type.parseId : undefined, })) ?? null, }, }) as never; }; inputFieldBuilder.globalID = function globalID( { for: forTypes, ...options }: GlobalIDInputFieldOptions = {} as never, ) { return this.id({ ...options, extensions: { ...options.extensions, isRelayGlobalID: true, relayGlobalIDFor: ( (forTypes && (Array.isArray(forTypes) ? forTypes : [forTypes])) as ObjectRef< SchemaTypes, unknown >[] )?.map((type: ObjectRef) => ({ typename: this.builder.configStore.getTypeConfig(type).name, parseId: 'parseId' in type ? type.parseId : undefined, })) ?? null, }, }) as never; }; inputFieldBuilder.connectionArgs = function connectionArgs() { return { before: this.field({ ...this.builder.options.relay?.beforeArgOptions, type: this.builder.options.relay?.cursorType ?? 'String', required: false, }), after: this.field({ ...this.builder.options.relay?.afterArgOptions, type: this.builder.options.relay?.cursorType ?? 'String', required: false, }), first: this.field({ ...this.builder.options.relay?.firstArgOptions, type: 'Int', required: false, }), last: this.field({ ...this.builder.options.relay?.lastArgOptions, type: 'Int', required: false, }), }; };