Пример #1
0
class User(ObjectType):
    id = external(Int(required=True))
    primary_email = external(String())
    uppercase_email = requires(String(), fields='primaryEmail')

    def resolve_uppercase_email(self, info):
        return self.primary_email.upper(
        ) if self.primary_email else self.primary_email
Пример #2
0
class FunnyText(ObjectType):
    class Meta:
        interfaces = (DecoratedText,)
    id = external(Int(required=True))

    def resolve_color(self, info, **kwargs):
        return self.id + 2
Пример #3
0
class ProfileNode(DjangoObjectType):
    class Meta:
        model = YouthProfile
        fields = ("id", )
        interfaces = (relay.Node, )
        filterset_class = ProfileFilter
        connection_class = CountConnection

    id = external(relay.GlobalID())
    youth_profile = graphene.Field(
        YouthProfileNode, description="Youth Profile related to the Profile")

    def resolve_youth_profile(self: YouthProfile, info, **kwargs):
        return self

    @login_required
    def __resolve_reference(self, info, **kwargs):
        profile = graphene.Node.get_node_from_global_id(info,
                                                        self.id,
                                                        only_type=ProfileNode)
        if not profile:
            return None

        user = info.context.user
        if user == profile.user or user_is_admin(user):
            return profile
        else:
            raise PermissionDenied(
                _("You do not have permission to perform this action."))

    @classmethod
    @login_required
    def get_node(cls, info, id):
        node = super().get_node(info, id)
        user = info.context.user
        if node and (user_is_admin(user) or node.user == user):
            return node
        return None
class Event(graphene.ObjectType):
    id = external(graphene.ID(required=True))
Пример #5
0
class Article(ObjectType):
    id = external(Int(required=True))
Пример #6
0
class User(graphene.ObjectType):
    # define key, use graphene.ID because this is the type used by graphene_mongo
    # set it to external
    id = external(graphene.ID())
Пример #7
0
class FileNode(ObjectType):
    id = external(Int(required=True))
Пример #8
0
class Message(graphene.ObjectType):
    id = external(graphene.Int(required=True))

    def resolve_id(self, **kwargs):
        return 1
Пример #9
0
class User(ObjectType):
    primaryEmail = external(String())
Пример #10
0
class Industry(ObjectType):
    sector = external(String(required=True))
Пример #11
0
class FunnyText(ObjectType):
    id = external(Int(required=True))
 class Meta:
     aggregate_id = external(TextField())
Пример #13
0
class ProfileNode(DjangoObjectType):
    """
    ProfileNode extended from the open-city-profile's ProfileNode.
    """
    class Meta:
        model = CustomerProfile
        fields = (
            "id",
            "invoicing_type",
            "comment",
            "organization",
            "boats",
            "berth_applications",
            "berth_leases",
            "winter_storage_applications",
            "winter_storage_leases",
            "orders",
            "offers",
        )
        interfaces = (relay.Node, )
        connection_class = CountConnection

    # explicitly mark shadowed ID field as external
    # otherwise, graphene-federation cannot catch it.
    # TODO: maybe later investigate other approaches for this?
    #  This one might or might not be the right one.
    id = external(relay.GlobalID())

    # The fields below come from our backend.
    # BEWARE: since ProfileNode is extended, none of its
    # fields could be non-nullable (i.e. required=True),
    # because then the entire ProfileNode will be null at
    # the federation level, if the profile object has no
    # object in our database.
    invoicing_type = InvoicingTypeEnum()
    comment = graphene.String()
    customer_group = CustomerGroupEnum()
    organization = graphene.Field(OrganizationNode)
    boats = DjangoConnectionField(BoatNode)
    berth_applications = DjangoFilterConnectionField(
        BerthApplicationNode,
        filterset_class=BerthApplicationFilter,
        description=
        "`BerthApplications` are ordered by `createdAt` in ascending order by default.",
    )
    berth_leases = DjangoConnectionField(BerthLeaseNode)
    winter_storage_applications = DjangoFilterConnectionField(
        WinterStorageApplicationNode,
        filterset_class=WinterStorageApplicationFilter,
        description=
        "`WinterStorageApplications` are ordered by `createdAt` in ascending order by default.",
    )
    winter_storage_leases = DjangoConnectionField(WinterStorageLeaseNode)
    orders = DjangoConnectionField("payments.schema.OrderNode")
    offers = DjangoConnectionField("payments.schema.BerthSwitchOfferNode")

    def resolve_berth_applications(self, info, **kwargs):
        return self.berth_applications.order_by("created_at")

    def resolve_winter_storage_applications(self, info, **kwargs):
        return self.winter_storage_applications.order_by("created_at")

    @login_required
    def __resolve_reference(self, info, **kwargs):
        profile = get_node_from_global_id(info, self.id, only_type=ProfileNode)
        return return_node_if_user_has_permissions(
            profile,
            info.context.user,
            CustomerProfile,
            BerthApplication,
            BerthLease,
            BerthSwitchOffer,
            Boat,
            Order,
            WinterStorageLease,
        )

    @classmethod
    @login_required
    def get_node(cls, info, id):
        node = super().get_node(info, id)
        return return_node_if_user_has_permissions(
            node,
            info.context.user,
            CustomerProfile,
            BerthApplication,
            BerthLease,
            BerthSwitchOffer,
            Boat,
            Order,
            WinterStorageLease,
        )