Skip to content

Commit

Permalink
fix(core): Fix struct custom field support on GlobalSettings
Browse files Browse the repository at this point in the history
Fixes #3381
  • Loading branch information
michaelbromley committed Feb 28, 2025
1 parent a4c1de2 commit 50a90e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
13 changes: 13 additions & 0 deletions packages/core/e2e/custom-field-struct.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ const customConfig = mergeConfig(testConfig(), {
],
},
],
// https://github.com/vendure-ecommerce/vendure/issues/3381
GlobalSettings: [
{
name: 'tipsPercentage',
type: 'struct',
list: true,
fields: [
{ name: 'percentage', type: 'float' },
{ name: 'name', type: 'string' },
{ name: 'isDefault', type: 'boolean' },
],
},
],
},
});

Expand Down
19 changes: 13 additions & 6 deletions packages/core/src/api/config/graphql-custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,23 @@ export function addGraphQLCustomFields(
`;
}

if (schema.getType(`Create${entityName}Input`)) {
if (writeableNonLocalizedFields.length) {
for (const structCustomField of structCustomFields) {
customFieldTypeDefs += `
const hasCreateInputType = schema.getType(`Create${entityName}Input`);
const hasUpdateInputType = schema.getType(`Update${entityName}Input`);

if ((hasCreateInputType || hasUpdateInputType) && writeableNonLocalizedFields.length) {
// Define any Struct input types that are required by
// the create and/or update input types.
for (const structCustomField of structCustomFields) {
customFieldTypeDefs += `
input ${getStructInputName(entityName, structCustomField)} {
${mapToStructFields(structCustomField.fields, wrapListType(getGraphQlInputType(entityName)))}
}
`;
}
}
}

if (hasCreateInputType) {
if (writeableNonLocalizedFields.length) {
customFieldTypeDefs += `
input Create${entityName}CustomFieldsInput {
${mapToFields(
Expand All @@ -172,7 +179,7 @@ export function addGraphQLCustomFields(
}
}

if (schema.getType(`Update${entityName}Input`)) {
if (hasUpdateInputType) {
if (writeableNonLocalizedFields.length) {
customFieldTypeDefs += `
input Update${entityName}CustomFieldsInput {
Expand Down

0 comments on commit 50a90e7

Please sign in to comment.