Skip to content

Commit

Permalink
feat(core): Expose entityCustomFields query
Browse files Browse the repository at this point in the history
Relates to #1848. This format allows us to support arbitrary entity names
when getting the custom field config in the Admin UI
  • Loading branch information
michaelbromley committed Jan 24, 2024
1 parent 0a566d3 commit 01f9d44
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 17 deletions.
22 changes: 21 additions & 1 deletion packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ export type AdministratorPaymentInput = {
};

export type AdministratorRefundInput = {
amount: Scalars['Money']['input'];
/**
* The amount to be refunded to this particular Payment. This was introduced in
* v2.2.0 as the preferred way to specify the refund amount. The `lines`, `shipping` and `adjustment`
* fields will be removed in a future version.
*/
amount?: InputMaybe<Scalars['Money']['input']>;
paymentId: Scalars['ID']['input'];
reason?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -1318,6 +1323,10 @@ export type CustomField = {

export type CustomFieldConfig = BooleanCustomFieldConfig | DateTimeCustomFieldConfig | FloatCustomFieldConfig | IntCustomFieldConfig | LocaleStringCustomFieldConfig | LocaleTextCustomFieldConfig | RelationCustomFieldConfig | StringCustomFieldConfig | TextCustomFieldConfig;

/**
* This type is deprecated in v2.2 in favor of the EntityCustomFields type,
* which allows custom fields to be defined on user-supplies entities.
*/
export type CustomFields = {
__typename?: 'CustomFields';
Address: Array<CustomFieldConfig>;
Expand Down Expand Up @@ -1563,6 +1572,12 @@ export type EmptyOrderLineSelectionError = ErrorResult & {
message: Scalars['String']['output'];
};

export type EntityCustomFields = {
__typename?: 'EntityCustomFields';
customFields: Array<CustomFieldConfig>;
entityName: Scalars['String']['output'];
};

export enum ErrorCode {
ALREADY_REFUNDED_ERROR = 'ALREADY_REFUNDED_ERROR',
CANCEL_ACTIVE_ORDER_ERROR = 'CANCEL_ACTIVE_ORDER_ERROR',
Expand Down Expand Up @@ -5714,7 +5729,12 @@ export type SellerSortParameter = {

export type ServerConfig = {
__typename?: 'ServerConfig';
/**
* This field is deprecated in v2.2 in favor of the entityCustomFields field,
* which allows custom fields to be defined on user-supplies entities.
*/
customFieldConfig: CustomFields;
entityCustomFields: Array<EntityCustomFields>;
moneyStrategyPrecision: Scalars['Int']['output'];
orderProcess: Array<OrderProcessState>;
permissions: Array<PermissionDefinition>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export type AdministratorPaymentInput = {
};

export type AdministratorRefundInput = {
amount: Scalars['Money']['input'];
/**
* The amount to be refunded to this particular Payment. This was introduced in
* v2.2.0 as the preferred way to specify the refund amount. The `lines`, `shipping` and `adjustment`
* fields will be removed in a future version.
*/
amount?: InputMaybe<Scalars['Money']['input']>;
paymentId: Scalars['ID']['input'];
reason?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -1273,6 +1278,10 @@ export type CustomField = {

export type CustomFieldConfig = BooleanCustomFieldConfig | DateTimeCustomFieldConfig | FloatCustomFieldConfig | IntCustomFieldConfig | LocaleStringCustomFieldConfig | LocaleTextCustomFieldConfig | RelationCustomFieldConfig | StringCustomFieldConfig | TextCustomFieldConfig;

/**
* This type is deprecated in v2.2 in favor of the EntityCustomFields type,
* which allows custom fields to be defined on user-supplies entities.
*/
export type CustomFields = {
Address: Array<CustomFieldConfig>;
Administrator: Array<CustomFieldConfig>;
Expand Down Expand Up @@ -1508,6 +1517,11 @@ export type EmptyOrderLineSelectionError = ErrorResult & {
message: Scalars['String']['output'];
};

export type EntityCustomFields = {
customFields: Array<CustomFieldConfig>;
entityName: Scalars['String']['output'];
};

export enum ErrorCode {
ALREADY_REFUNDED_ERROR = 'ALREADY_REFUNDED_ERROR',
CANCEL_ACTIVE_ORDER_ERROR = 'CANCEL_ACTIVE_ORDER_ERROR',
Expand Down Expand Up @@ -5488,7 +5502,12 @@ export type SellerSortParameter = {
};

export type ServerConfig = {
/**
* This field is deprecated in v2.2 in favor of the entityCustomFields field,
* which allows custom fields to be defined on user-supplies entities.
*/
customFieldConfig: CustomFields;
entityCustomFields: Array<EntityCustomFields>;
moneyStrategyPrecision: Scalars['Int']['output'];
orderProcess: Array<OrderProcessState>;
permissions: Array<PermissionDefinition>;
Expand Down
22 changes: 21 additions & 1 deletion packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export type AdministratorPaymentInput = {
};

export type AdministratorRefundInput = {
amount: Scalars['Money']['input'];
/**
* The amount to be refunded to this particular Payment. This was introduced in
* v2.2.0 as the preferred way to specify the refund amount. The `lines`, `shipping` and `adjustment`
* fields will be removed in a future version.
*/
amount?: InputMaybe<Scalars['Money']['input']>;
paymentId: Scalars['ID']['input'];
reason?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -1306,6 +1311,10 @@ export type CustomField = {

export type CustomFieldConfig = BooleanCustomFieldConfig | DateTimeCustomFieldConfig | FloatCustomFieldConfig | IntCustomFieldConfig | LocaleStringCustomFieldConfig | LocaleTextCustomFieldConfig | RelationCustomFieldConfig | StringCustomFieldConfig | TextCustomFieldConfig;

/**
* This type is deprecated in v2.2 in favor of the EntityCustomFields type,
* which allows custom fields to be defined on user-supplies entities.
*/
export type CustomFields = {
__typename?: 'CustomFields';
Address: Array<CustomFieldConfig>;
Expand Down Expand Up @@ -1551,6 +1560,12 @@ export type EmptyOrderLineSelectionError = ErrorResult & {
message: Scalars['String']['output'];
};

export type EntityCustomFields = {
__typename?: 'EntityCustomFields';
customFields: Array<CustomFieldConfig>;
entityName: Scalars['String']['output'];
};

export enum ErrorCode {
ALREADY_REFUNDED_ERROR = 'ALREADY_REFUNDED_ERROR',
CANCEL_ACTIVE_ORDER_ERROR = 'CANCEL_ACTIVE_ORDER_ERROR',
Expand Down Expand Up @@ -5636,7 +5651,12 @@ export type SellerSortParameter = {

export type ServerConfig = {
__typename?: 'ServerConfig';
/**
* This field is deprecated in v2.2 in favor of the entityCustomFields field,
* which allows custom fields to be defined on user-supplies entities.
*/
customFieldConfig: CustomFields;
entityCustomFields: Array<EntityCustomFields>;
moneyStrategyPrecision: Scalars['Int']['output'];
orderProcess: Array<OrderProcessState>;
permissions: Array<PermissionDefinition>;
Expand Down
64 changes: 63 additions & 1 deletion packages/core/e2e/custom-fields.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,68 @@ describe('Custom fields', () => {
});
});

it('globalSettings.serverConfig.entityCustomFields', async () => {
const { globalSettings } = await adminClient.query(gql`
query {
globalSettings {
serverConfig {
entityCustomFields {
entityName
customFields {
... on CustomField {
name
type
list
}
}
}
}
}
}
`);

const productCustomFields = globalSettings.serverConfig.entityCustomFields.find(
e => e.entityName === 'Product',
);
expect(productCustomFields).toEqual({
entityName: 'Product',
customFields: [
{ name: 'nullable', type: 'string', list: false },
{ name: 'notNullable', type: 'string', list: false },
{ name: 'stringWithDefault', type: 'string', list: false },
{ name: 'localeStringWithDefault', type: 'localeString', list: false },
{ name: 'intWithDefault', type: 'int', list: false },
{ name: 'floatWithDefault', type: 'float', list: false },
{ name: 'booleanWithDefault', type: 'boolean', list: false },
{ name: 'dateTimeWithDefault', type: 'datetime', list: false },
{ name: 'validateString', type: 'string', list: false },
{ name: 'validateLocaleString', type: 'localeString', list: false },
{ name: 'validateInt', type: 'int', list: false },
{ name: 'validateFloat', type: 'float', list: false },
{ name: 'validateDateTime', type: 'datetime', list: false },
{ name: 'validateFn1', type: 'string', list: false },
{ name: 'validateFn2', type: 'string', list: false },
{ name: 'validateFn3', type: 'string', list: false },
{ name: 'validateFn4', type: 'string', list: false },
{ name: 'validateRelation', type: 'relation', list: false },
{ name: 'stringWithOptions', type: 'string', list: false },
{ name: 'nullableStringWithOptions', type: 'string', list: false },
{ name: 'nonPublic', type: 'string', list: false },
{ name: 'public', type: 'string', list: false },
{ name: 'longString', type: 'string', list: false },
{ name: 'longLocaleString', type: 'localeString', list: false },
{ name: 'readonlyString', type: 'string', list: false },
{ name: 'stringList', type: 'string', list: true },
{ name: 'localeStringList', type: 'localeString', list: true },
{ name: 'stringListWithDefault', type: 'string', list: true },
{ name: 'intListWithValidation', type: 'int', list: true },
{ name: 'uniqueString', type: 'string', list: false },
// The internal type should not be exposed at all
// { name: 'internalString', type: 'string' },
],
});
});

it('get nullable with no default', async () => {
const { product } = await adminClient.query(gql`
query {
Expand Down Expand Up @@ -470,7 +532,7 @@ describe('Custom fields', () => {
}
}
`);
}, 'The custom field "stringWithOptions" value ["tiny"] is invalid. Valid options are [\'small\', \'medium\', \'large\']'),
}, "The custom field \"stringWithOptions\" value [\"tiny\"] is invalid. Valid options are ['small', 'medium', 'large']"),
);

it('valid string option', async () => {
Expand Down
Loading

0 comments on commit 01f9d44

Please sign in to comment.