CustomFields
CustomFields
Most entities can have additional fields added to them by defining an array of CustomFieldConfig objects on against the corresponding key.
Configuration options
All custom fields share some common properties:
name: string
: The name of the field.type: string
: A string of type CustomFieldType.list: boolean
: If set totrue
, then the field will be an array of the specified type.label?: LocalizedString[]
: An array of localized labels for the field.description?: LocalizedString[]
: An array of localized descriptions for the field.public?: boolean
: Whether or not the custom field is available via the Shop API. Defaults totrue
.readonly?: boolean
: Whether or not the custom field can be updated via the GraphQL APIs. Defaults tofalse
.internal?: boolean
: Whether or not the custom field is exposed at all via the GraphQL APIs. Defaults tofalse
.defaultValue?: any
: The default value when an Entity is created with this field.nullable?: boolean
: Whether the field is nullable in the database. If set tofalse
, then adefaultValue
should be provided.unique?: boolean
: Whether the value of the field should be unique. When set totrue
, a UNIQUE constraint is added to the column. Defaults tofalse
.validate?: (value: any) => string | LocalizedString[] | void
: A custom validation function. If the value is valid, then the function should not return a value. If a string or LocalizedString array is returned, this is interpreted as an error message.
The LocalizedString
type looks like this:
type LocalizedString = {
languageCode: LanguageCode;
value: string;
};
In addition to the common properties, the following field types have some type-specific properties:
string
type
pattern?: string
: A regex pattern which the field value must matchoptions?: { value: string; label?: LocalizedString[]; };
: An array of pre-defined options for the field.length?: number
: The max length of the varchar created in the database. Defaults to 255. Maximum is 65,535.
localeString
type
pattern?: string
: A regex pattern which the field value must matchlength?: number
: The max length of the varchar created in the database. Defaults to 255. Maximum is 65,535.
int
& float
type
min?: number
: The minimum permitted valuemax?: number
: The maximum permitted valuestep?: number
: The step value
datetime
type
The min, max & step properties for datetime fields are intended to be used as described in the datetime-local docs
min?: string
: The earliest permitted datemax?: string
: The latest permitted datestep?: string
: The step value
relation
type
entity: VendureEntity
: The entity which this custom field is referencingeager?: boolean
: Whether to eagerly load the relation. Defaults to false.graphQLType?: string
: The name of the GraphQL type that corresponds to the entity. Can be omitted if it is the same, which is usually the case.
Example
bootstrap({
// ...
customFields: {
Product: [
{ name: 'infoUrl', type: 'string' },
{ name: 'downloadable', type: 'boolean', defaultValue: false },
{ name: 'shortName', type: 'localeString' },
],
User: [
{ name: 'socialLoginToken', type: 'string', public: false },
],
},
})
Signature
interface CustomFields {
Address?: CustomFieldConfig[];
Administrator?: CustomFieldConfig[];
Asset?: CustomFieldConfig[];
Channel?: CustomFieldConfig[];
Collection?: CustomFieldConfig[];
Country?: CustomFieldConfig[];
Customer?: CustomFieldConfig[];
CustomerGroup?: CustomFieldConfig[];
Facet?: CustomFieldConfig[];
FacetValue?: CustomFieldConfig[];
Fulfillment?: CustomFieldConfig[];
GlobalSettings?: CustomFieldConfig[];
Order?: CustomFieldConfig[];
OrderLine?: CustomFieldConfig[];
PaymentMethod?: CustomFieldConfig[];
Product?: CustomFieldConfig[];
ProductOption?: CustomFieldConfig[];
ProductOptionGroup?: CustomFieldConfig[];
ProductVariant?: CustomFieldConfig[];
Promotion?: CustomFieldConfig[];
ShippingMethod?: CustomFieldConfig[];
TaxCategory?: CustomFieldConfig[];
TaxRate?: CustomFieldConfig[];
User?: CustomFieldConfig[];
Zone?: CustomFieldConfig[];
}
Members
Address
CustomFieldConfig[]
Administrator
CustomFieldConfig[]
Asset
CustomFieldConfig[]
Channel
CustomFieldConfig[]
Collection
CustomFieldConfig[]
Country
CustomFieldConfig[]
Customer
CustomFieldConfig[]
CustomerGroup
CustomFieldConfig[]
Facet
CustomFieldConfig[]
FacetValue
CustomFieldConfig[]
Fulfillment
CustomFieldConfig[]
GlobalSettings
CustomFieldConfig[]
Order
CustomFieldConfig[]
OrderLine
CustomFieldConfig[]
PaymentMethod
CustomFieldConfig[]
Product
CustomFieldConfig[]
ProductOption
CustomFieldConfig[]
ProductOptionGroup
CustomFieldConfig[]
ProductVariant
CustomFieldConfig[]
Promotion
CustomFieldConfig[]
ShippingMethod
CustomFieldConfig[]
TaxCategory
CustomFieldConfig[]
TaxRate
CustomFieldConfig[]
User
CustomFieldConfig[]
Zone
CustomFieldConfig[]