Skip to content

Commit

Permalink
fix(core): Always include customFields on OrderAddress type
Browse files Browse the repository at this point in the history
Closes #616
  • Loading branch information
michaelbromley committed Jan 8, 2021
1 parent d1e4bb2 commit c5e3c6d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/core/src/api/config/graphql-custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} {
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit c5e3c6d

Please sign in to comment.