Example #1
0
class RiskReport(graphene_django.DjangoObjectType):
    id = relay.GlobalID(
        description='A global ID that relay uses for reactive paging purposes',
    )
    report_id = graphene.ID(
        description='The ID of the risk report',
        required=True,
    )
    company_id = graphene.UUID(
        description=
        'The company, as identified by the UUID, of the risk report',
        required=True,
    )
    risk_score = graphene.Float(
        description='The risk score of the company',
        required=True,
    )
    risk_rating = graphene.String(
        description='The risk rating of the company',
        required=True,
    )
    date_time = graphene.DateTime(
        description='The date and time of the risk report',
        required=True,
    )

    class Meta:
        model = RiskReportModel
        interfaces = (relay.Node, )
        description = 'A risk report'
Example #2
0
class ItemInterface(graphene.Interface):
    id = relay.GlobalID()
    parent_id = relay.GlobalID()
    foo = graphene.String()
    title = graphene.String()
    unoptimized_title = graphene.String()
    item_type = graphene.String()
    father = graphene.Field('tests.schema.ItemType')
    all_children = graphene.List('tests.schema.ItemType')
    children_names = graphene.String()
    aux_children_names = graphene.String()
    filtered_children = graphene.List(
        'tests.schema.ItemType',
        name=graphene.String(required=True),
    )
    children_custom_filtered = gql_optimizer.field(
        ConnectionField('tests.schema.ItemConnection',
                        filter_input=ItemFilterInput()),
        prefetch_related=_prefetch_children,
    )

    def resolve_foo(root, info):
        return 'bar'

    @gql_optimizer.resolver_hints(
        model_field=lambda: 'children', )
    def resolve_children_names(root, info):
        return ' '.join(item.name for item in root.children.all())

    @gql_optimizer.resolver_hints(
        prefetch_related='children', )
    def resolve_aux_children_names(root, info):
        return ' '.join(item.name for item in root.children.all())

    @gql_optimizer.resolver_hints(
        prefetch_related=lambda info, name: Prefetch(
            'children',
            queryset=gql_optimizer.query(Item.objects.filter(name=name), info),
            to_attr='gql_filtered_children_' + name,
        ),
    )
    def resolve_filtered_children(root, info, name):
        return getattr(root, 'gql_filtered_children_' + name)

    def resolve_children_custom_filtered(root, info, *_args):
        return getattr(root, 'gql_custom_filtered_children')
Example #3
0
class FinancialReport(graphene_django.DjangoObjectType):
    id = relay.GlobalID(
        description='A global ID that relay uses for reactive paging purposes',
    )
    report_id = graphene.ID(
        description='The ID of the financial report',
        required=True,
    )
    company_id = graphene.UUID(
        description=
        'The company, as identified by the UUID, of the financial report',
        required=True,
    )
    date_time = graphene.DateTime(
        description='The date and time of the report',
        required=True,
    )
    currency = graphene.String(
        description='The currency that the report uses',
        required=True,
    )
    financial_data = graphene.List(
        of_type=graphene.NonNull(of_type=FinancialData),
        description='A list of financial data',
        required=True,
    )
    financial_ratios = graphene.List(
        of_type=graphene.NonNull(of_type=FinancialRatio),
        description='A list of financial ratios',
        required=True,
    )

    class Meta:
        model = FinancialReportModel
        interfaces = (relay.Node, )
        description = 'A financial report'

    def resolve_financial_data(
        self: FinancialReportModel,
        info: graphql.ResolveInfo,
        **kwargs,
    ) -> List[FinancialDataModel]:
        logging.debug(f'self={self}, info={info}, kwargs={kwargs}')
        return self.financial_data.all()

    def resolve_financial_ratios(
        self: FinancialReportModel,
        info: graphql.ResolveInfo,
        **kwargs,
    ) -> List[FinancialRatioModel]:
        logging.debug(f'self={self}, info={info}, kwargs={kwargs}')
        return self.financial_ratios.all()
Example #4
0
class News(DjangoObjectType):
    id = relay.GlobalID(description='A global ID that relay uses for reactive paging purposes', )
    news_id = graphene.ID(description='The ID of the news snippet', required=True, )
    company_id = graphene.UUID(
        description='The company, as identified by the UUID, of the news snippet',
        required=True,
    )
    title = graphene.String(description='The title of the news snippet', required=True, )
    date_time = graphene.DateTime(description='The date and time of the news snippet', required=True, )
    snippet = graphene.String(description='A snippet of the news', required=True, )
    url = graphene.String(description='The URL where the news originated', required=True, )

    class Meta:
        model = NewsModel
        interfaces = (relay.Node,)
        description = 'A news snippet'
Example #5
0
class Company(graphene_django.DjangoObjectType):
    id = relay.GlobalID(
        description='A global ID for reactive paging purposes', )
    company_id = graphene.UUID(description='The UUID of the company', )
    name = graphene.String(description='The name of the company', )
    industry = graphene.String(
        description='The industry in which the company operates', )
    description = graphene.String(description='A description of the company', )
    exchange = graphene.String(
        description='The stock exchange in which the company is listed', )

    # TODO figure out the proper type for country
    # country = graphene.Enum(description='The country in which the company operates',)

    class Meta:
        model = CompanyModel
        interfaces = (relay.Node, )
        description = 'General information about a company'
Example #6
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 ItemInterface(graphene.Interface):
    id = relay.GlobalID()
    parent_id = relay.GlobalID()
    foo = graphene.String()
    title = graphene.String()
    unoptimized_title = graphene.String()
    item_type = graphene.String()
    father = graphene.Field("tests.schema.ItemType")
    all_children = graphene.List("tests.schema.ItemType")
    children_names = graphene.String()
    aux_children_names = graphene.String()
    filtered_children = graphene.List(
        "tests.schema.ItemType",
        name=graphene.String(required=True),
    )
    aux_filtered_children = graphene.List(
        "tests.schema.ItemType",
        name=graphene.String(required=True),
    )
    children_custom_filtered = gql_optimizer.field(
        ConnectionField("tests.schema.ItemConnection", filter_input=ItemFilterInput()),
        prefetch_related=_prefetch_children,
    )

    def resolve_foo(root, info):
        return "bar"

    @gql_optimizer.resolver_hints(
        model_field=lambda: "children",
    )
    def resolve_children_names(root, info):
        return " ".join(item.name for item in root.children.all())

    @gql_optimizer.resolver_hints(
        prefetch_related="children",
    )
    def resolve_aux_children_names(root, info):
        return " ".join(item.name for item in root.children.all())

    @gql_optimizer.resolver_hints(
        prefetch_related=lambda info, name: Prefetch(
            "children",
            queryset=gql_optimizer.query(Item.objects.filter(name=name), info),
            to_attr="gql_filtered_children_" + name,
        ),
    )
    def resolve_filtered_children(root, info, name):
        return getattr(root, "gql_filtered_children_" + name)

    @gql_optimizer.resolver_hints(
        prefetch_related=lambda info, name: Prefetch(
            "children",
            queryset=gql_optimizer.query(
                Item.objects.filter(name=f"some_prefix {name}"), info
            ),
            # Different queryset than resolve_filtered_children but same to_attr, on purpose
            # to check equality of Prefetch is based only on to_attr attribute, as it is implemented in Django.
            to_attr="gql_filtered_children_" + name,
        ),
    )
    def resolve_aux_filtered_children(root, info, name):
        return getattr(root, "gql_filtered_children_" + name)

    def resolve_children_custom_filtered(root, info, *_args):
        return getattr(root, "gql_custom_filtered_children")
Example #8
0
 class Input:
     shortcut_id = relay.GlobalID(required=True)
     redirect_uri = graphene.String(required=True)
Example #9
0
 class Input:
     name = graphene.String(required=True)
     layout_id = relay.GlobalID(required=True)
Example #10
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,
        )