Explorar el Código

fix(core): Fix schema error with readonly Address custom field

Fixes #3326
Michael Bromley hace 1 año
padre
commit
1bddbcc60c

+ 10 - 0
packages/core/e2e/custom-fields.e2e-spec.ts

@@ -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,
 });
 

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

@@ -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)
@@ -257,7 +258,7 @@ export function addGraphQLCustomFields(
                 }
             `;
         }
-        if (schema.getType('UpdateOrderAddressInput')) {
+        if (schema.getType('UpdateOrderAddressInput') && writeablePublicAddressFields?.length) {
             customFieldTypeDefs += `
                 extend input UpdateOrderAddressInput {
                     customFields: UpdateAddressCustomFieldsInput