Skip to content

Commit

Permalink
fix(core): Fix schema error with readonly Address custom field
Browse files Browse the repository at this point in the history
Fixes #3326
  • Loading branch information
michaelbromley committed Jan 21, 2025
1 parent c970dea commit 1bddbcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/core/e2e/custom-fields.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ const customConfig = mergeConfig(testConfig(), {
{ name: 'secretKey2', type: 'string', defaultValue: '', public: false, internal: false },
],
OrderLine: [{ name: 'validateInt', type: 'int', min: 0, max: 10 }],
// Single readonly Address custom field to test
// https://github.com/vendure-ecommerce/vendure/issues/3326
Address: [
{
name: 'hereId',
type: 'string',
readonly: true,
nullable: true,
},
],
} as CustomFields,
});

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/api/config/graphql-custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export function addGraphQLCustomFields(
const publicAddressFields = customFieldConfig.Address?.filter(
config => !config.internal && (publicOnly === true ? config.public !== false : true),
);
const writeablePublicAddressFields = publicAddressFields?.filter(field => !field.readonly);
if (publicAddressFields?.length) {
// For custom fields on the Address entity, we also extend the OrderAddress
// type (which is used to store address snapshots on Orders)
Expand All @@ -257,7 +258,7 @@ export function addGraphQLCustomFields(
}
`;
}
if (schema.getType('UpdateOrderAddressInput')) {
if (schema.getType('UpdateOrderAddressInput') && writeablePublicAddressFields?.length) {
customFieldTypeDefs += `
extend input UpdateOrderAddressInput {
customFields: UpdateAddressCustomFieldsInput
Expand Down

0 comments on commit 1bddbcc

Please sign in to comment.