Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add checkout filed to User type in GraphQl
fowczarek6527bc410ad7
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex ff8b788d35..8cf4592adf 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -5,7 +5,9 @@ from graphene import relayfrom graphql_jwt.decorators import permission_requiredfrom ...account import models+from ...checkout.utils import get_user_cartfrom ...core.permissions import get_permissions+from ..checkout.types import Checkoutfrom ..core.connection import CountableDjangoObjectTypefrom ..core.fields import PrefetchingConnectionFieldfrom ..core.types import CountryDisplay, PermissionDisplay@@ -45,6 +47,9 @@ class User(CountableDjangoObjectType):addresses = gql_optimizer.field(graphene.List(Address, description='List of all user\'s addresses.'),model_field='addresses')+ checkout = graphene.Field(+ Checkout,+ description='Returns the last open checkout of this user.')note = graphene.String(description='A note about the customer')orders = gql_optimizer.field(PrefetchingConnectionField(@@ -64,6 +69,9 @@ class User(CountableDjangoObjectType):def resolve_addresses(self, info, **kwargs):return self.addresses.all()+ def resolve_checkout(self, info, **kwargs):+ return get_user_cart(self)+def resolve_permissions(self, info, **kwargs):if self.is_superuser:permissions = get_permissions()