feat: add ValidateCartMutation extension points - #3441
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR exposes the source VTEX ChangesCart validation extensions
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SDK
participant GraphQL
participant ValidateCartResolver
participant VTEX
SDK->>GraphQL: Request validation fragments
GraphQL->>ValidateCartResolver: Execute ValidateCartMutation
ValidateCartResolver->>VTEX: Convert OrderForm
VTEX-->>ValidateCartResolver: Return OrderForm
ValidateCartResolver-->>GraphQL: Return cart with custom fields
GraphQL-->>SDK: Return validated cart
SDK->>SDK: Map validated cart with getCartFromValidatedCart
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/sdk/cart/index.ts`:
- Line 34: Update validateCart and the Cart type to preserve root-level fields
from StoreCartAdditional when constructing the SDK result, including custom
fields such as total, coupon, and totalizers. Apply the same preservation in
useReorder, while excluding these extension fields from input comparison and
update mapping. Add a regression test verifying one custom cart field survives
validation.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c3aee1ba-f933-4a4b-a184-0cdcb98ead9a
⛔ Files ignored due to path filters (2)
packages/core/@generated/gql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**packages/core/@generated/graphql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**
📒 Files selected for processing (5)
packages/api/src/platforms/vtex/resolvers/root.tspackages/api/src/platforms/vtex/resolvers/validateCart.tspackages/core/README.mdpackages/core/src/customizations/src/fragments/ValidateCartMutation.tspackages/core/src/sdk/cart/index.ts
|

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
FastStore's native
ValidateCartMutationdoes not provide extension points for stores that need to expose additional data from the VTEX orderForm, such as custom item fields, cart totals, coupons, or totalizers.This PR adds extension points for
StoreOfferandStoreCart, allowing stores to include custom cart data while keeping FastStore's native cart reconciliation as the source of truth.How it works?
ValidateCartMutationnow includes two extension fragments:CartItemAdditionalfor extendingStoreOfferStoreCartAdditionalfor extendingStoreCartStores can extend the GraphQL schema and include their custom fields in these fragments.
Example:
Cart-level fields that depend on the VTEX orderForm can be resolved through
StoreCartRoot:These additional fields are only exposed in the GraphQL response.
The existing cart reconciliation, item comparison, local cart handling, and orderForm update behavior remain unchanged.
How to test it?
pnpm --filter @faststore/api exec vitest run test/integration/schema.test.ts test/integration/mutations.test.tspnpm --filter @faststore/core testpnpm exec biome check packages/api/src/platforms/vtex/resolvers/root.ts packages/api/src/platforms/vtex/resolvers/validateCart.ts packages/core/src/sdk/cart/index.ts packages/core/src/customizations/src/fragments/ValidateCartMutation.ts packages/core/README.mdIn a FastStore store:
Extend
StoreOfferand/orStoreCartinsrc/graphql/vtex/typeDefs.Add the custom fields to
CartItemAdditionaland/orStoreCartAdditional.Add custom resolvers when the fields depend on the VTEX orderForm.
Execute
ValidateCartMutation.Confirm that native and custom cart fields are returned together.
Confirm that cart reconciliation still works when local cart data differs from the orderForm.
Starters Deploy Preview
Not available yet.
The feature can be tested using a FastStore store configured with this PR branch.
References
Extending the FastStore API schema](https://developers.vtex.com/docs/guides/faststore/api-extensions-extending-api-schema)
Extending FastStore queries using fragments](https://developers.vtex.com/docs/guides/faststore/api-extensions-extending-queries-using-fragments)
packages/core/src/sdk/cart/index.tspackages/core/src/customizations/src/fragments/ValidateCartMutation.tspackages/api/src/platforms/vtex/resolvers/validateCart.tsSummary by CodeRabbit
New Features
Documentation
Summary by CodeRabbit
New Features
Documentation
Tests