Browse Source

fix(core): Always include customFields on OrderAddress type

Closes #616
Michael Bromley 5 years ago
parent
commit
c5e3c6da46
1 changed files with 18 additions and 10 deletions
  1. 18 10
      packages/core/src/api/config/graphql-custom-fields.ts

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

@@ -61,16 +61,6 @@ export function addGraphQLCustomFields(
                         customFields: ${entityName}CustomFields
                     }
                 `;
-
-                // For custom fields on the Address entity, we also extend the OrderAddress
-                // type (which is used to store address snapshots on Orders)
-                if (entityName === 'Address' && schema.getType('OrderAddress')) {
-                    customFieldTypeDefs += `
-                        extend type OrderAddress {
-                            customFields: ${entityName}CustomFields
-                        }
-                    `;
-                }
             } else {
                 customFieldTypeDefs += `
                     extend type ${entityName} {
@@ -178,6 +168,24 @@ export function addGraphQLCustomFields(
         }
     }
 
+    if (customFieldConfig.Address?.length) {
+        // For custom fields on the Address entity, we also extend the OrderAddress
+        // type (which is used to store address snapshots on Orders)
+        if (schema.getType('OrderAddress')) {
+            customFieldTypeDefs += `
+                extend type OrderAddress {
+                    customFields: AddressCustomFields
+                }
+            `;
+        }
+    } else {
+        customFieldTypeDefs += `
+            extend type OrderAddress {
+                customFields: JSON
+            }
+        `;
+    }
+
     return extendSchema(schema, parse(customFieldTypeDefs));
 }