Skip to content
On this page

This is an auto-generated document to support extension builders understand the internal packages they can utilize. To find our written guides, tutorials, and API/SDK reference, check out our main docs .

Directus / @directus/sdk / rest / createField

Function: createField()

createField<Schema, TQuery>(collection, item, query?): RestCommand<IfAny<Schema, Record<string, any>, Merge<MappedFunctionFields<Schema, DirectusField<Schema>> extends FF ? MapFlatFields<DirectusField<Schema>, FieldsWildcard<DirectusField<Schema>, Exclude<UnpackList<Mutable<TQuery["fields"]>>, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : AllKeys<UnpackList<UnpackList<Mutable<TQuery["fields"]>>> extends Field ? Field extends object ? Field : never : never>>>, FF extends Record<string, string> ? FF : Record<string, string>> : never, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : { [Field in string | number | symbol]: Field extends keyof DirectusField<Schema> ? Extract<DirectusField<Schema>[Field], ItemType<Schema>> extends RelatedCollection ? IsNullable<DirectusField<Schema>[Field], null | (RelatedCollection extends any[] ? HasManyToAnyRelation<RelatedCollection> extends never ? null | ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>[] : ApplyManyToAnyFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field], UnpackList<RelatedCollection>>[] : ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>), RelatedCollection extends any[] ? HasManyToAnyRelation<RelatedCollection> extends never ? null | ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>[] : ApplyManyToAnyFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field], UnpackList<RelatedCollection>>[] : ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>> : never : never }>>, Schema>

Create a new field in the given collection.

Type parameters

Schema extends object

TQuery extends Query<Schema, DirectusField<Schema>>

Parameters

collection: keyof Schema

The collection to create a field for

item: NestedPartial<DirectusField<Schema>>

The field to create

query?: TQuery

Optional return data query

Returns

RestCommand<IfAny<Schema, Record<string, any>, Merge<MappedFunctionFields<Schema, DirectusField<Schema>> extends FF ? MapFlatFields<DirectusField<Schema>, FieldsWildcard<DirectusField<Schema>, Exclude<UnpackList<Mutable<TQuery["fields"]>>, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : AllKeys<UnpackList<UnpackList<Mutable<TQuery["fields"]>>> extends Field ? Field extends object ? Field : never : never>>>, FF extends Record<string, string> ? FF : Record<string, string>> : never, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : { [Field in string | number | symbol]: Field extends keyof DirectusField<Schema> ? Extract<DirectusField<Schema>[Field], ItemType<Schema>> extends RelatedCollection ? IsNullable<DirectusField<Schema>[Field], null | (RelatedCollection extends any[] ? HasManyToAnyRelation<RelatedCollection> extends never ? null | ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>[] : ApplyManyToAnyFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field], UnpackList<RelatedCollection>>[] : ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>), RelatedCollection extends any[] ? HasManyToAnyRelation<RelatedCollection> extends never ? null | ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>[] : ApplyManyToAnyFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field], UnpackList<RelatedCollection>>[] : ApplyNestedQueryFields<Schema, RelatedCollection, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>>[Field]>> : never : never }>>, Schema>

The field object for the created field.

Source

rest/commands/create/fields.ts:21