Skip to content

Commit fdec628

Browse files
refactor(core): Share the CustomFieldsInput type-name suffix
The '*CustomFieldsInput' naming convention was a literal in both the schema generation and the interceptor's schema-driven discovery. Extract it to a single exported constant so the two sides cannot drift apart on a rename. Relates to #2648
1 parent d530ef9 commit fdec628

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/core/src/api/config/graphql-custom-fields.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111

1212
import {
1313
BaseTypedCustomFieldConfig,
14+
CUSTOM_FIELDS_INPUT_TYPE_SUFFIX,
1415
CustomFieldConfig,
1516
CustomFields,
1617
isNonListRelationCustomField,
@@ -163,7 +164,7 @@ export function addGraphQLCustomFields(
163164

164165
if (hasCreateInputType) {
165166
if (writeableNonLocalizedFields.length) {
166-
const createCustomFieldsInputType = `Create${entityName}CustomFieldsInput`;
167+
const createCustomFieldsInputType = `Create${entityName}${CUSTOM_FIELDS_INPUT_TYPE_SUFFIX}`;
167168
if (!schema.getType(createCustomFieldsInputType)) {
168169
customFieldTypeDefs += `
169170
input ${createCustomFieldsInputType} {
@@ -201,7 +202,7 @@ export function addGraphQLCustomFields(
201202

202203
if (hasUpdateInputType) {
203204
if (writeableNonLocalizedFields.length) {
204-
const updateCustomFieldsInputType = `Update${entityName}CustomFieldsInput`;
205+
const updateCustomFieldsInputType = `Update${entityName}${CUSTOM_FIELDS_INPUT_TYPE_SUFFIX}`;
205206
if (!schema.getType(updateCustomFieldsInputType)) {
206207
customFieldTypeDefs += `
207208
input ${updateCustomFieldsInputType} {

packages/core/src/api/middleware/custom-field-processing-interceptor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import {
1919
import { UserInputError } from '../../common/error/errors';
2020
import { Injector } from '../../common/injector';
2121
import { ConfigService } from '../../config/config.service';
22-
import { CustomFieldConfig, CustomFields } from '../../config/custom-field/custom-field-types';
22+
import {
23+
CUSTOM_FIELDS_INPUT_TYPE_SUFFIX,
24+
CustomFieldConfig,
25+
CustomFields,
26+
} from '../../config/custom-field/custom-field-types';
2327
import { parseContext } from '../common/parse-context';
2428
import { internal_getRequestContext, RequestContext } from '../common/request-context';
2529
import { validateCustomFieldValue } from '../common/validate-custom-field-value';
@@ -216,7 +220,7 @@ export class CustomFieldProcessingInterceptor implements NestInterceptor {
216220
return cached;
217221
}
218222
const map = new Map<string, Set<string>>();
219-
const suffix = 'CustomFieldsInput';
223+
const suffix = CUSTOM_FIELDS_INPUT_TYPE_SUFFIX;
220224
const entityNames = (Object.keys(this.configService.customFields) as Array<keyof CustomFields>).sort(
221225
(a, b) => (b as string).length - (a as string).length,
222226
);

packages/core/src/config/custom-field/custom-field-types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ import { RequestContext } from '../../api/common/request-context';
3333
import { Injector } from '../../common/injector';
3434
import { VendureEntity } from '../../entity/base/base.entity';
3535

36+
/**
37+
* The suffix of every generated GraphQL input type that carries an entity's custom fields, e.g.
38+
* `UpdateProductCustomFieldsInput`. It is the single source of this naming convention, shared by the
39+
* schema generation (which produces these types) and the custom-field processing interceptor (which
40+
* discovers them). If this changes, both sides change together.
41+
*/
42+
export const CUSTOM_FIELDS_INPUT_TYPE_SUFFIX = 'CustomFieldsInput';
43+
3644
// prettier-ignore
3745
export type DefaultValueType<T extends CustomFieldType | StructFieldType> =
3846
T extends 'string' | 'localeString' | 'text' | 'localeText' ? string :

0 commit comments

Comments
 (0)