-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add cart updated subscription #6671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cart updated subscription #6671
Conversation
|
09c0e07 to
96da22e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me except a bunch of spelling errors in test descriptions. Would want @aldeed to look at it as well
packages/api-plugin-carts/src/resolvers/Subscription/accountCartUpdate.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-carts/src/resolvers/Subscription/accountCartUpdate.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-carts/src/resolvers/Subscription/accountCartUpdate.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-carts/src/resolvers/Subscription/anonymousCartUpdate.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-carts/src/resolvers/Subscription/anonymousCartUpdate.test.js
Outdated
Show resolved
Hide resolved
packages/api-plugin-carts/src/util/publishCartUpdatedEvent.test.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be nice to have available! I left some suggestions, mostly about patterns and naming.
packages/api-plugin-carts/src/resolvers/Subscription/anonymousCartUpdate.js
Outdated
Show resolved
Hide resolved
| if (cart.accountId) { | ||
| context.pubSub.publish("ACCOUNT_CART_UPDATED", { accountCartUpdate: cart }); | ||
| } else { | ||
| context.pubSub.publish("ANONYMOUS_CART_UPDATED", { anonymousCartUpdate: cart }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems fine for both of these to pass { cart } rather than separate names accountCartUpdate and anonymousCartUpdate. The subscriptions could also then share the same filter function if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might even consider simplifying this to emit CART_UPDATED always, and then filter on cart.accountId in each subscription resolver instead. There are probably pros and cons to each approach, performance vs. consumer complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vanpho93 I still think this should be simplified further to:
context.pubSub.publish("CART_UPDATED", { cart });Otherwise it is unnecessary complexity for the event consumer to check for both anonymousCartUpdate and accountCartUpdate when they often will not care what type of cart it is. If they do care, they can check it with if (cart.accountId) in the consumer function.
For example, if you make this change, then your account cart subscription filter can just be:
export function filter(payload, variables) {
const { cart } = payload;
const { accountId, shopId } = variables;
return cart.accountId === accountId && cart.shopId === shopId;
}15a0f76 to
f9509eb
Compare
be6ad3f to
5554ec6
Compare
f9509eb to
8dcc827
Compare
5554ec6 to
09ae49a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment response about using cart as the event payload property. Otherwise looking good.
Signed-off-by: vanpho93 <[email protected]>
09ae49a to
1ac6ba9
Compare
|
@aldeed Updated, can you take another look? |
Resolves #6437
Impact: major
Type: feature
Issue
Unable to notify client when cart changed.
Solution
Add GraphQL Subscription to cart