Skip to content

Commit

Permalink
fix(core): Fix custom field relation for ProductVariant when value is…
Browse files Browse the repository at this point in the history
… null (#2727)

Fixes #2723
  • Loading branch information
andriinuts authored Mar 18, 2024
1 parent 8a961b0 commit b4f8a55
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/core/e2e/custom-field-relations.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,43 @@ describe('Custom field relations', () => {
});
});

it('ProductVariant without a specified property value returns null', async () => {
const { createProduct } = await adminClient.query(gql`
mutation {
createProduct(
input: {
translations: [
{
languageCode: en
name: "Product with empty custom fields"
description: ""
slug: "product-with-empty-custom-fields"
}
]
}
) {
id
}
}
`);

const { product } = await adminClient.query(gql`
query {
product(id: "${createProduct.id}") {
id
customFields {
cfProductVariant{
price
currencyCode
priceWithTax
}
}
}
}`);

expect(product.customFields.cfProductVariant).toEqual(null);
});

describe('entity-specific implementation', () => {
function assertCustomFieldIds(customFields: any, single: string, multi: string[]) {
expect(customFields.single).toEqual({ id: single });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class CustomFieldRelationResolverService {
result: VendureEntity | VendureEntity[] | null,
fieldDef: RelationCustomFieldConfig,
) {
if (result == null) return null;

if (fieldDef.entity === ProductVariant) {
if (Array.isArray(result)) {
await Promise.all(result.map(r => this.applyVariantPrices(ctx, r as any)));
Expand Down

0 comments on commit b4f8a55

Please sign in to comment.