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[];
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[];
Region?: CustomFieldConfig[];
Seller?: CustomFieldConfig[];
ShippingMethod?: CustomFieldConfig[];
StockLocation?: CustomFieldConfig[];
TaxCategory?: CustomFieldConfig[];
TaxRate?: CustomFieldConfig[];
User?: CustomFieldConfig[];
Zone?: CustomFieldConfig[];
}
Members
Address
property
type:
CustomFieldConfig[]
Administrator
property
type:
CustomFieldConfig[]
Asset
property
type:
CustomFieldConfig[]
Channel
property
type:
CustomFieldConfig[]
Collection
property
type:
CustomFieldConfig[]
Customer
property
type:
CustomFieldConfig[]
CustomerGroup
property
type:
CustomFieldConfig[]
Facet
property
type:
CustomFieldConfig[]
FacetValue
property
type:
CustomFieldConfig[]
Fulfillment
property
type:
CustomFieldConfig[]
GlobalSettings
property
type:
CustomFieldConfig[]
Order
property
type:
CustomFieldConfig[]
OrderLine
property
type:
CustomFieldConfig[]
PaymentMethod
property
type:
CustomFieldConfig[]
Product
property
type:
CustomFieldConfig[]
ProductOption
property
type:
CustomFieldConfig[]
ProductOptionGroup
property
type:
CustomFieldConfig[]
ProductVariant
property
type:
CustomFieldConfig[]
Promotion
property
type:
CustomFieldConfig[]
Region
property
type:
CustomFieldConfig[]
Seller
property
type:
CustomFieldConfig[]
ShippingMethod
property
type:
CustomFieldConfig[]
StockLocation
property
type:
CustomFieldConfig[]
TaxCategory
property
type:
CustomFieldConfig[]
TaxRate
property
type:
CustomFieldConfig[]
User
property
type:
CustomFieldConfig[]
Zone
property
type:
CustomFieldConfig[]