Skip to content

Conversation

michaelbromley
Copy link
Member

@michaelbromley michaelbromley commented Jul 16, 2025

Description

Fixes #3391

When you have custom fields on the OrderLine entity, and use the adjustOrderLine mutation to update the values, Vendure will now merge those values with any existing values that already are set on the given OrderLine.

Breaking changes

Although this is more of a bug fix (the old behaviour is usually undesirable),
it is listed as a breaking change in the unlikely case that someone relies on
the existing behaviour. In this case, you'll need to explicitly set null
values for any custom fields that you want to "remove".

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Summary by CodeRabbit

  • Documentation

    • Expanded the custom fields guide with a new "Special cases" section, detailing additional automatic API changes for specific entities when custom fields are defined.
    • Improved formatting and readability throughout the guide.
  • Bug Fixes

    • Enhanced the update behavior for custom fields on order lines, ensuring that only explicitly changed fields are updated while others are preserved.
  • Tests

    • Added comprehensive end-to-end tests for order line custom fields, covering creation, updating, unsetting, and edge cases.
    • Updated test file imports and formatting for consistency.
    • Excluded new test files from certain code generation processes.

Fixes #3391.

BREAKING CHANGE: when using the `adjustOrderLine` mutation and passing custom fields,
the values you pass will now be _merged_ with any existing custom field values.
Previously, the custom fields object would completely _replace_ any existing values.

Although this is more of a bug fix (the old behaviour is usually undesirable),
it is listed as a breaking change in the unlikely case that someone relies on
the existing behaviour. In this case, you'll need to explicitly set `null`
values for any custom fields that you want to "remove".
Copy link

vercel bot commented Jul 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Jul 16, 2025 10:01am

Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes introduce a merge strategy for updating customFields on OrderLine entities during the adjustOrderLine mutation, ensuring only specified fields are updated or unset, while others are preserved. Related end-to-end tests are added, documentation is expanded to clarify API behaviors with custom fields, and minor formatting and codegen adjustments are made.

Changes

File(s) Change Summary
docs/docs/guides/developer-guide/custom-fields/index.md Added "Special cases" section detailing automatic API changes for custom fields; formatting and whitespace fixes
packages/core/e2e/custom-fields.e2e-spec.ts Consolidated imports, reordered import members, minor formatting in custom field config array
packages/core/e2e/order-line-custom-fields.e2e-spec.ts New e2e test suite for OrderLine custom fields: setup, mutations, and tests for create/update/merge semantics
packages/core/src/service/services/order.service.ts Modified adjustOrderLines to merge incoming customFields with existing ones, preserving unspecified fields
scripts/codegen/generate-graphql-types.ts Excluded new test file from codegen by adding to ignore list

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ShopAPI
    participant OrderService
    participant DB

    Client->>ShopAPI: adjustOrderLine(orderLineId, customFields)
    ShopAPI->>OrderService: adjustOrderLines(orderLineId, customFields)
    OrderService->>DB: Fetch existing OrderLine
    OrderService->>OrderService: Merge customFields (overwrite, unset, preserve)
    OrderService->>DB: Update OrderLine with merged customFields
    OrderService->>ShopAPI: Return updated OrderLine
    ShopAPI->>Client: Response with updated customFields
Loading

Assessment against linked issues

Objective Addressed Explanation
Merge customFields on OrderLine during adjustOrderLine mutation instead of replacing ( #3391 )
Ensure relational custom fields are handled correctly in the merge ( #3391 )
Add tests to verify custom field merging and edge cases ( #3391 )

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Documentation formatting and special cases section (docs/docs/guides/developer-guide/custom-fields/index.md) While helpful, documentation changes are not strictly required by the issue's objectives.
Import reordering and formatting in unrelated e2e test (packages/core/e2e/custom-fields.e2e-spec.ts) These changes are unrelated to the fix for customFields merge logic in adjustOrderLine.
Codegen ignore list update (scripts/codegen/generate-graphql-types.ts) Excluding the new test from codegen is not specified in the linked issue objectives.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-16T10_02_00_890Z-debug-0.log


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/docs/guides/developer-guide/custom-fields/index.md (1)

1350-1382: Fix list style consistency.

The unordered lists in this section use dashes while the rest of the document uses asterisks.

Apply this diff to maintain consistency:

-- Shop API: [addItemToOrder](/reference/graphql-api/shop/mutations#additemtoorder) will have a 3rd input argument, `customFields`, which allows custom field values to be set when adding an item to the order.
-- Shop API: [adjustOrderLine](/reference/graphql-api/shop/mutations#additemtoorder) will have a 3rd input argument, `customFields`, which allows custom field values to be updated.
-- Admin API: the equivalent mutations for manipulating draft orders and for modifying and order will also have inputs to allow custom field values to be set.
+* Shop API: [addItemToOrder](/reference/graphql-api/shop/mutations#additemtoorder) will have a 3rd input argument, `customFields`, which allows custom field values to be set when adding an item to the order.
+* Shop API: [adjustOrderLine](/reference/graphql-api/shop/mutations#additemtoorder) will have a 3rd input argument, `customFields`, which allows custom field values to be updated.
+* Admin API: the equivalent mutations for manipulating draft orders and for modifying and order will also have inputs to allow custom field values to be set.
-- Admin API: [modifyOrder](/reference/graphql-api/admin/mutations#modifyorder) will have a `customFields` field on the input object.
+* Admin API: [modifyOrder](/reference/graphql-api/admin/mutations#modifyorder) will have a `customFields` field on the input object.
-- Shop API: [eligibleShippingMethods](/reference/graphql-api/shop/queries#eligibleshippingmethods) will have public custom fields available on the result.
+* Shop API: [eligibleShippingMethods](/reference/graphql-api/shop/queries#eligibleshippingmethods) will have public custom fields available on the result.
-- Shop API: [eligiblePaymentMethods](/reference/graphql-api/shop/queries#eligiblepaymentmethods) will have public custom fields available on the result.
+* Shop API: [eligiblePaymentMethods](/reference/graphql-api/shop/queries#eligiblepaymentmethods) will have public custom fields available on the result.
-- Shop API: [registerCustomerAccount](/reference/graphql-api/shop/mutations#registercustomeraccount) will have have a `customFields` field on the input
-  object.
+* Shop API: [registerCustomerAccount](/reference/graphql-api/shop/mutations#registercustomeraccount) will have have a `customFields` field on the input
+  object.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb8b3c2 and f54384e.

📒 Files selected for processing (5)
  • docs/docs/guides/developer-guide/custom-fields/index.md (16 hunks)
  • packages/core/e2e/custom-fields.e2e-spec.ts (2 hunks)
  • packages/core/e2e/order-line-custom-fields.e2e-spec.ts (1 hunks)
  • packages/core/src/service/services/order.service.ts (1 hunks)
  • scripts/codegen/generate-graphql-types.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
scripts/codegen/generate-graphql-types.ts (1)
Learnt from: CR
PR: vendure-ecommerce/vendure#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-01T07:36:12.107Z
Learning: Applies to packages/dashboard/src/**/*.{ts,tsx} : Do not use explicit typings or generic parameters with useQuery or useMutation; rely on type inference from the graphql function.
packages/core/e2e/custom-fields.e2e-spec.ts (2)
Learnt from: CR
PR: vendure-ecommerce/vendure#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-01T07:36:12.107Z
Learning: Applies to packages/dashboard/src/**/*.{js,jsx,ts,tsx} : When creating useQuery calls, follow the documented pattern: import { api } from '@/graphql/api.js', import { graphql } from '@/graphql/graphql.js', and use useQuery from '@tanstack/react-query' with the graphql document and api.query.
Learnt from: CR
PR: vendure-ecommerce/vendure#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-01T07:36:12.107Z
Learning: Applies to packages/dashboard/src/**/*.{js,jsx,ts,tsx} : When creating useMutation calls, follow the documented pattern: import { api } from '@/graphql/api.js', import { graphql } from '@/graphql/graphql.js', and use useMutation from '@tanstack/react-query' with the graphql document and api.mutate.
docs/docs/guides/developer-guide/custom-fields/index.md (1)
Learnt from: CR
PR: vendure-ecommerce/vendure#0
File: .cursor/rules/dashboard.mdc:0-0
Timestamp: 2025-07-01T07:36:12.107Z
Learning: Applies to packages/dashboard/src/**/*.{js,jsx,ts,tsx} : For forms, prefer using the FormFieldWrapper component (the custom wrapper around Shadcn react-hook-form components) over raw Shadcn components.
🪛 markdownlint-cli2 (0.17.2)
docs/docs/guides/developer-guide/custom-fields/index.md

1350-1350: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1351-1351: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1352-1352: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1362-1362: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1368-1368: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1374-1374: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


1380-1380: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: e2e tests (22.x, mysql)
  • GitHub Check: e2e tests (20.x, mysql)
  • GitHub Check: e2e tests (20.x, mariadb)
  • GitHub Check: unit tests (22.x)
  • GitHub Check: codegen / codegen
  • GitHub Check: unit tests (24.x)
  • GitHub Check: unit tests (20.x)
  • GitHub Check: build (20.x)
  • GitHub Check: build (22.x)
  • GitHub Check: build (24.x)
  • GitHub Check: publish_install (macos-latest, 24.x)
  • GitHub Check: publish_install (windows-latest, 24.x)
  • GitHub Check: publish_install (ubuntu-latest, 24.x)
  • GitHub Check: publish_install (windows-latest, 20.x)
  • GitHub Check: publish_install (windows-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 22.x)
  • GitHub Check: publish_install (macos-latest, 20.x)
  • GitHub Check: publish_install (macos-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
packages/core/src/service/services/order.service.ts (1)

784-804: Excellent implementation of the custom fields merge strategy!

The implementation correctly addresses the PR objective by merging custom fields instead of replacing them entirely. The logic properly handles:

  • Preserving existing custom field values when not explicitly changed
  • Allowing explicit null values to unset fields
  • Ignoring undefined values to maintain existing data
  • Using the merged fields for relation updates

The code is well-documented and follows a clear, logical flow.

scripts/codegen/generate-graphql-types.ts (1)

37-37: LGTM! Correct exclusion of the new test file.

Adding the new order-line-custom-fields.e2e-spec to the ignore list is appropriate since end-to-end test specification files should not be included in the GraphQL type generation process.

packages/core/e2e/custom-fields.e2e-spec.ts (1)

7-7: LGTM! Clean formatting improvements.

The import consolidation and formatting fixes improve code consistency.

Also applies to: 10-10, 194-195

docs/docs/guides/developer-guide/custom-fields/index.md (2)

21-21: LGTM! Formatting improvements enhance readability.

The consistent spacing around commas and braces improves code readability throughout the documentation.

Also applies to: 64-72, 91-101, 114-122, 194-195, 354-358, 383-386, 560-563, 634-636, 702-704, 965-967, 1195-1208, 1216-1218, 1264-1270


1342-1382: Excellent documentation of special API behaviors!

This new section clearly explains the automatic API extensions that occur when custom fields are defined on specific entities. The information about OrderLine custom fields directly supports the PR's merging functionality.

packages/core/e2e/order-line-custom-fields.e2e-spec.ts (1)

1-373: Excellent test coverage for the new merging behavior!

This comprehensive test suite thoroughly validates the custom fields merging functionality:

  • Tests all custom field types (string, int, boolean, nullable, relation)
  • Validates partial updates preserve existing values
  • Confirms explicit null unsets fields
  • Covers edge cases with empty objects
  • Ensures proper test isolation with beforeEach cleanup

The tests clearly demonstrate the breaking change behavior where users must now explicitly set fields to null to remove them.

@michaelbromley michaelbromley merged commit ead7bfa into minor Jul 16, 2025
36 checks passed
@michaelbromley michaelbromley deleted the orderline-custom-field-merge branch July 16, 2025 11:13
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant