class Input: amount = graphene.Float(required=True) # If missing (undefined), then set to None category = graphene.GlobalID(required=False) company = graphene.GlobalID(required=False) card = graphene.GlobalID(required=False) note = graphene.String(required=False) skipSummaryFlag = graphene.Int(required=False) timeCreated = graphene.String(required=False)
class Input: frequency = EnumRecurringBillFrequency(required=True) recurring_month = graphene.Int(required=True) recurring_day = graphene.Int(required=True) amount = graphene.Float(required=True) category = graphene.GlobalID(required=False) company = graphene.GlobalID(required=False) card = graphene.GlobalID(required=False) note = graphene.String(required=False) skipSummaryFlag = graphene.Int(required=False)
class Channel(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) is_active = graphene.Boolean(required=True) slug = graphene.String(required=True) currency_code = graphene.String(required=True) slug = graphene.String(required=True) has_orders = graphene.Boolean( required=True, description="Whether a channel has associated orders.") default_country = graphene.Field( CountryDisplay, description= (f"{ADDED_IN_31} Default country for the channel. Default country can be " "used in checkout to determine the stock quantities or calculate taxes " "when the country was not explicitly provided."), required=True, ) class Meta: description = "Represents channel." model = models.Channel interfaces = [graphene.relay.Node] @staticmethod @permission_required(ChannelPermissions.MANAGE_CHANNELS) def resolve_has_orders(root: models.Channel, info): return (ChannelWithHasOrdersByIdLoader(info.context).load( root.id).then(lambda channel: channel.has_orders)) @staticmethod def resolve_default_country(root: models.Channel, _info): return CountryDisplay(code=root.default_country.code, country=root.default_country.name)
class OrderDiscount(ModelObjectType): id = graphene.GlobalID(required=True) type = OrderDiscountTypeEnum(required=True) name = graphene.String() translated_name = graphene.String() value_type = graphene.Field( DiscountValueTypeEnum, required=True, description="Type of the discount: fixed or percent", ) value = PositiveDecimal( required=True, description= "Value of the discount. Can store fixed value or percent value", ) reason = graphene.String( required=False, description="Explanation for the applied discount.") amount = graphene.Field(Money, description="Returns amount of discount.", required=True) class Meta: description = ( "Contains all details related to the applied discount to the order." ) interfaces = [relay.Node] model = models.OrderDiscount @staticmethod @permission_required(OrderPermissions.MANAGE_ORDERS) def resolve_reason(root: models.OrderDiscount, _info): return root.reason
class EventDelivery(ModelObjectType): id = graphene.GlobalID(required=True) created_at = graphene.DateTime(required=True) status = EventDeliveryStatusEnum(description="Event delivery status.", required=True) event_type = WebhookEventTypeEnum(description="Webhook event type.", required=True) attempts = FilterConnectionField( EventDeliveryAttemptCountableConnection, sort_by=EventDeliveryAttemptSortingInput( description="Event delivery sorter"), description="Event delivery attempts.", ) payload = graphene.String(description="Event payload.") class Meta: description = "Event delivery." model = core_models.EventDelivery interfaces = [graphene.relay.Node] @staticmethod def resolve_attempts(root: core_models.EventDelivery, info, **kwargs): qs = core_models.EventDeliveryAttempt.objects.filter(delivery=root) qs = filter_connection_queryset(qs, kwargs) return create_connection_slice( qs, info, kwargs, EventDeliveryAttemptCountableConnection) @staticmethod def resolve_payload(root: core_models.EventDelivery, info): if not root.payload_id: return None return PayloadByIdLoader(info.context).load(root.payload_id)
class DigitalContent(ModelObjectType): id = graphene.GlobalID(required=True) use_default_settings = graphene.Boolean(required=True) automatic_fulfillment = graphene.Boolean(required=True) content_file = graphene.String(required=True) max_downloads = graphene.Int() url_valid_days = graphene.Int() urls = NonNullList( lambda: DigitalContentUrl, description="List of URLs for the digital variant.", ) product_variant = graphene.Field( "saleor.graphql.product.types.products.ProductVariant", required=True, description="Product variant assigned to digital content.", ) class Meta: model = models.DigitalContent interfaces = (relay.Node, ObjectWithMetadata) @staticmethod def resolve_urls(root: models.DigitalContent, _info): return root.urls.all() @staticmethod def resolve_product_variant(root: models.DigitalContent, info): return (ProductVariantByIdLoader(info.context).load( root.product_variant_id).then(lambda variant: ChannelContext( node=variant, channel_slug=None)))
class AttributeTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) class Meta: model = attribute_models.AttributeTranslation interfaces = [graphene.relay.Node]
class ShippingMethodTranslatableContent(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) description = JSONString( description="Description of the shipping method." + RICH_CONTENT) translation = TranslationField(ShippingMethodTranslation, type_name="shipping method") shipping_method = PermissionsField( "saleor.graphql.shipping.types.ShippingMethodType", description= ("Shipping method are the methods you'll use to get customer's orders " " to them. They are directly exposed to the customers."), deprecation_reason= (f"{DEPRECATED_IN_3X_FIELD} Get model fields from the root level queries." ), permissions=[ ShippingPermissions.MANAGE_SHIPPING, ], ) class Meta: model = shipping_models.ShippingMethod interfaces = [graphene.relay.Node] @staticmethod def resolve_shipping_method(root: shipping_models.ShippingMethod, _info): return ChannelContext(node=root, channel_slug=None)
class SaleTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String() class Meta: model = discount_models.SaleTranslation interfaces = [graphene.relay.Node]
class ProductVariantTranslatableContent(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) translation = TranslationField(ProductVariantTranslation, type_name="product variant") product_variant = graphene.Field( "saleor.graphql.product.types.products.ProductVariant", description=( "Represents a version of a product such as different size or color." ), deprecation_reason= (f"{DEPRECATED_IN_3X_FIELD} Get model fields from the root level queries." ), ) attribute_values = NonNullList( AttributeValueTranslatableContent, required=True, description= "List of product variant attribute values that can be translated.", ) class Meta: model = product_models.ProductVariant interfaces = [graphene.relay.Node] @staticmethod def resolve_product_variant(root: product_models.ProductVariant, info): return ChannelContext(node=root, channel_slug=None) @staticmethod def resolve_attribute_values(root: product_models.ProductVariant, info): return (SelectedAttributesByProductVariantIdLoader(info.context).load( root.id).then(get_translatable_attribute_values))
class CategoryTranslatableContent(ModelObjectType): id = graphene.GlobalID(required=True) seo_title = graphene.String() seo_description = graphene.String() name = graphene.String(required=True) description = JSONString(description="Description of the category." + RICH_CONTENT) description_json = JSONString( description="Description of the category." + RICH_CONTENT, deprecation_reason=( f"{DEPRECATED_IN_3X_FIELD} Use the `description` field instead."), ) translation = TranslationField(CategoryTranslation, type_name="category") category = graphene.Field( "saleor.graphql.product.types.products.Category", description="Represents a single category of products.", deprecation_reason= (f"{DEPRECATED_IN_3X_FIELD} Get model fields from the root level queries." ), ) class Meta: model = product_models.Category interfaces = [graphene.relay.Node] @staticmethod def resolve_category(root: product_models.Category, _info): return root @staticmethod def resolve_description_json(root: product_models.Category, _info): description = root.description return description if description is not None else {}
class Input(BerthServicesInput): id = graphene.GlobalID( required=True, description= "`GlobalID` associated to the Open City Profile customer profile", ) organization = OrganizationInput()
class ProductVariantTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) class Meta: model = product_models.ProductVariantTranslation interfaces = [graphene.relay.Node]
class FinanceInvoiceInterface(graphene.Interface): id = graphene.GlobalID() subtotal_display = graphene.String() tax_display = graphene.String() total_display = graphene.String() paid_display = graphene.String() balance_display = graphene.String()
class Fulfillment(ModelObjectType): id = graphene.GlobalID(required=True) fulfillment_order = graphene.Int(required=True) status = FulfillmentStatusEnum(required=True) tracking_number = graphene.String(required=True) created = graphene.DateTime(required=True) lines = NonNullList(FulfillmentLine, description="List of lines for the fulfillment.") status_display = graphene.String( description="User-friendly fulfillment status.") warehouse = graphene.Field( Warehouse, required=False, description="Warehouse from fulfillment was fulfilled.", ) class Meta: description = "Represents order fulfillment." interfaces = [relay.Node, ObjectWithMetadata] model = models.Fulfillment @staticmethod def resolve_lines(root: models.Fulfillment, _info): return root.lines.all() @staticmethod def resolve_status_display(root: models.Fulfillment, _info): return root.get_status_display() @staticmethod def resolve_warehouse(root: models.Fulfillment, _info): line = root.lines.first() return line.stock.warehouse if line and line.stock else None
class MenuItemTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) class Meta: model = menu_models.MenuItemTranslation interfaces = [graphene.relay.Node]
class Page(ModelObjectType): id = graphene.GlobalID(required=True) seo_title = graphene.String() seo_description = graphene.String() title = graphene.String(required=True) content = JSONString(description="Content of the page." + RICH_CONTENT) publication_date = graphene.Date( deprecation_reason=( f"{DEPRECATED_IN_3X_FIELD} " "Use the `publishedAt` field to fetch the publication date." ), ) published_at = graphene.DateTime( description="The page publication date." + ADDED_IN_33 ) is_published = graphene.Boolean(required=True) slug = graphene.String(required=True) page_type = graphene.Field(PageType, required=True) created = graphene.DateTime(required=True) content_json = JSONString( description="Content of the page." + RICH_CONTENT, deprecation_reason=f"{DEPRECATED_IN_3X_FIELD} Use the `content` field instead.", required=True, ) translation = TranslationField(PageTranslation, type_name="page") attributes = NonNullList( SelectedAttribute, required=True, description="List of attributes assigned to this product.", ) class Meta: description = ( "A static page that can be manually added by a shop operator through the " "dashboard." ) interfaces = [graphene.relay.Node, ObjectWithMetadata] model = models.Page @staticmethod def resolve_publication_date(root: models.Page, _info): return root.published_at @staticmethod def resolve_created(root: models.Page, _info): return root.created_at @staticmethod def resolve_page_type(root: models.Page, info): return PageTypeByIdLoader(info.context).load(root.page_type_id) @staticmethod def resolve_content_json(root: models.Page, _info): content = root.content return content if content is not None else {} @staticmethod def resolve_attributes(root: models.Page, info): return SelectedAttributesByPageIdLoader(info.context).load(root.id)
class ShopTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) header_text = graphene.String(required=True) description = graphene.String(required=True) class Meta: model = site_models.SiteSettingsTranslation interfaces = [graphene.relay.Node]
class Account(SQLAlchemyObjectType, AccountAttributes): """Account info""" id = graphene.GlobalID(description="ID of the account") class Meta: model = AccountModel interfaces = (graphene.relay.Node, ) only_fields = ("email", )
class GiftCardTag(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) class Meta: description = "The gift card tag." + ADDED_IN_31 + PREVIEW_FEATURE model = models.GiftCardTag interfaces = [graphene.relay.Node]
class ShippingMethodTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String() description = graphene.JSONString() class Meta: model = shipping_models.ShippingMethodTranslation interfaces = [graphene.relay.Node]
class OrganizationNodeInterface(graphene.Interface): id = graphene.GlobalID() url_logo_login = graphene.String() # url_logo_login_thumbnail_small = graphene.String() url_logo_invoice = graphene.String() url_logo_email = graphene.String() url_logo_shop_header = graphene.String() url_logo_self_checkin = graphene.String()
class AttributeValueTranslation(BaseTranslationType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) rich_text = JSONString(description="Attribute value." + RICH_CONTENT) class Meta: model = attribute_models.AttributeValueTranslation interfaces = [graphene.relay.Node]
class Warehouse(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) slug = graphene.String(required=True) email = graphene.String(required=True) is_private = graphene.Boolean(required=True) address = graphene.Field("saleor.graphql.account.types.Address", required=True) company_name = graphene.String( required=True, description="Warehouse company name.", deprecation_reason=( f"{DEPRECATED_IN_3X_FIELD} Use `Address.companyName` instead."), ) click_and_collect_option = WarehouseClickAndCollectOptionEnum( description=( f"{ADDED_IN_31} Click and collect options: local, all or disabled. " f"{PREVIEW_FEATURE}"), required=True, ) shipping_zones = ConnectionField( "saleor.graphql.shipping.types.ShippingZoneCountableConnection", required=True, ) class Meta: description = "Represents warehouse." model = models.Warehouse interfaces = [graphene.relay.Node, ObjectWithMetadata] @staticmethod def resolve_shipping_zones(root, info, *_args, **kwargs): from ..shipping.types import ShippingZoneCountableConnection instances = root.shipping_zones.all() slice = create_connection_slice(instances, info, kwargs, ShippingZoneCountableConnection) edges_with_context = [] for edge in slice.edges: node = edge.node edge.node = ChannelContext(node=node, channel_slug=None) edges_with_context.append(edge) slice.edges = edges_with_context return slice @staticmethod def resolve_address(root, info): return AddressByIdLoader(info.context).load(root.address_id) @staticmethod def resolve_company_name(root, info, *_args, **_kwargs): def _resolve_company_name(address): return address.company_name return (AddressByIdLoader(info.context).load( root.address_id).then(_resolve_company_name))
class PageType(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) slug = graphene.String(required=True) attributes = NonNullList( Attribute, description="Page attributes of that page type." ) available_attributes = FilterConnectionField( AttributeCountableConnection, filter=AttributeFilterInput(), description="Attributes that can be assigned to the page type.", permissions=[ PagePermissions.MANAGE_PAGES, ], ) has_pages = PermissionsField( graphene.Boolean, description="Whether page type has pages assigned.", permissions=[ PagePermissions.MANAGE_PAGES, ], ) class Meta: description = ( "Represents a type of page. It defines what attributes are available to " "pages of this type." ) interfaces = [graphene.relay.Node, ObjectWithMetadata] model = models.PageType @staticmethod def get_model(): return models.PageType @staticmethod def resolve_attributes(root: models.PageType, info): return PageAttributesByPageTypeIdLoader(info.context).load(root.pk) @staticmethod def resolve_available_attributes(root: models.PageType, info, **kwargs): qs = attribute_models.Attribute.objects.get_unassigned_page_type_attributes( root.pk ) qs = filter_connection_queryset(qs, kwargs, info.context) return create_connection_slice(qs, info, kwargs, AttributeCountableConnection) @staticmethod def resolve_has_pages(root: models.PageType, info): return ( PagesByPageTypeIdLoader(info.context) .load(root.pk) .then(lambda pages: bool(pages)) ) @staticmethod def __resolve_references(roots: List["PageType"], _info): return resolve_federation_references(PageType, roots, models.PageType.objects)
class ScheduleEventTicketNodeInterface(graphene.Interface): id = graphene.GlobalID() price_display = graphene.String() is_sold_out = graphene.Boolean() is_earlybird_price = graphene.Boolean() earlybird_discount = graphene.types.Decimal() earlybird_discount_display = graphene.String() total_price = graphene.types.Decimal() total_price_display = graphene.String()
class Input(BerthServicesInput): id = graphene.GlobalID(required=True) organization = OrganizationInput( description= "With the values provided, the Organization associated to the Profile " "will be either created or updated as required.") delete_organization = graphene.Boolean( description="If `true` is passed, the organization will be deleted." )
def __init_subclass_with_meta__( cls, form_class=None, model=None, fields=ALL_FIELDS, permission_classes=None, return_field_name=None, deleting=False, is_relay=False, **options ): if form_class and not model: model = form_class._meta.model if not model: raise Exception("model is required for DjangoModelMutation") if not form_class: form_class = model_forms.modelform_factory(model, fields=fields) input_fields = {} if not deleting: form = form_class() input_fields = fields_for_form(form, fields) if fields == ALL_FIELDS or "id" in fields or deleting: if is_relay: input_fields["id"] = graphene.GlobalID() else: input_fields["id"] = graphene.ID() registry = get_global_registry() model_type = registry.get_type_for_model(model) if not model_type: raise Exception("No type registered for model: {}".format(model.__name__)) if not return_field_name: model_name = model.__name__ return_field_name = model_name[:1].lower() + model_name[1:] output_fields = OrderedDict() output_fields[return_field_name] = graphene.Field(model_type) _meta = DjangoModelMutationOptions(cls) _meta.form_class = form_class _meta.fields = fields _meta.model = model _meta.permission_classes = permission_classes or () _meta.return_field_name = return_field_name _meta.deleting = deleting _meta.is_relay = is_relay _meta.fields = yank_fields_from_attrs(output_fields, _as=Field) input_fields = yank_fields_from_attrs(input_fields, _as=InputField) super(DjangoModelMutation, cls).__init_subclass_with_meta__( _meta=_meta, input_fields=input_fields, **options )
class AppInstallation(ModelObjectType): id = graphene.GlobalID(required=True) app_name = graphene.String(required=True) manifest_url = graphene.String(required=True) class Meta: model = models.AppInstallation description = "Represents ongoing installation of app." interfaces = [graphene.relay.Node, Job]
class Webhook(ModelObjectType): id = graphene.GlobalID(required=True) name = graphene.String(required=True) events = NonNullList( WebhookEvent, description="List of webhook events.", deprecation_reason= (f"{DEPRECATED_IN_3X_FIELD} Use `asyncEvents` or `syncEvents` instead." ), required=True, ) sync_events = NonNullList( WebhookEventSync, description="List of synchronous webhook events.", required=True, ) async_events = NonNullList( WebhookEventAsync, description="List of asynchronous webhook events.", required=True, ) app = graphene.Field("saleor.graphql.app.types.App", required=True) event_deliveries = FilterConnectionField( EventDeliveryCountableConnection, sort_by=EventDeliverySortingInput( description="Event delivery sorter."), filter=EventDeliveryFilterInput( description="Event delivery filter options."), description="Event deliveries.", ) target_url = graphene.String(required=True) is_active = graphene.Boolean(required=True) secret_key = graphene.String() class Meta: description = "Webhook." model = models.Webhook interfaces = [graphene.relay.Node] @staticmethod def resolve_async_events(root: models.Webhook, *_args, **_kwargs): return root.events.filter(event_type__in=WebhookEventAsyncType.ALL) @staticmethod def resolve_sync_events(root: models.Webhook, *_args, **_kwargs): return root.events.filter(event_type__in=WebhookEventSyncType.ALL) @staticmethod def resolve_events(root: models.Webhook, *_args, **_kwargs): return root.events.all() @staticmethod def resolve_event_deliveries(root: models.Webhook, info, *_args, **kwargs): qs = core_models.EventDelivery.objects.filter(webhook_id=root.pk) qs = filter_connection_queryset(qs, kwargs) return create_connection_slice(qs, info, kwargs, EventDeliveryCountableConnection)