You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by theocerutti August 9, 2024
Hello,
When we create a cart with a custom CART_QUERY_FRAGMENT it creates an incorrect ts typing.
Actually, even with your DEFAULT_CART_QUERY_FRAGMENT the typing is not correct.
If we have to modify the behavior of the cart it's really annoying since we have to override almost every cart types and that's because of almost one big issue.
So if we create a cart with custom query:
exportconstCUSTOM_CART_QUERY_FRAGMENT=`#graphqlfragment CustomCartApiQuery on Cart { id checkoutUrl totalQuantity}`;constcartHandler=createCartHandler({
storefront,getCartId: cartGetIdDefault(request.headers),setCartId: cartSetIdDefault(),cartQueryFragment: CUSTOM_CART_QUERY_FRAGMENT,cartMutateFragment: CUSTOM_CART_QUERY_FRAGMENT,});
Indeed we shouldn't have Cart as type but the real queried fragment: CustomCartApiQueryFragment in this case.
also CartGetProps should allow to add more custom fields since we could add parameter to cart query fragment:
it would be nice to have a dynamic CartGetProps: we could "read" the custom query fragment and add variable type dynamically to CartGetProps.
otherwise just add a extraQueryVariables prop:
type CartGetProps = {
...
extraQueryVariables: any[];
};
The text was updated successfully, but these errors were encountered:
The cart handler came out shortly after we had codegen but its typing was a bit complex and never got proper support. I think it's possible but probably not an easy change in TS.
Discussed in #2416
Originally posted by theocerutti August 9, 2024
Hello,
When we create a cart with a custom
CART_QUERY_FRAGMENT
it creates an incorrect ts typing.Actually, even with your
DEFAULT_CART_QUERY_FRAGMENT
the typing is not correct.If we have to modify the behavior of the cart it's really annoying since we have to override almost every cart types and that's because of almost one big issue.
So if we create a cart with custom query:
Then theses types:
should be:
Indeed we shouldn't have
Cart
as type but the real queried fragment:CustomCartApiQueryFragment
in this case.also
CartGetProps
should allow to add more custom fields since we could add parameter to cart query fragment:it would be nice to have a dynamic
CartGetProps
: we could "read" the custom query fragment and add variable type dynamically toCartGetProps
.otherwise just add a
extraQueryVariables
prop:The text was updated successfully, but these errors were encountered: