Пример #1
0
class AuthedQuery(AbstractType, QueryResolver):
    menu_list = filter.DjangoFilterConnectionField(MenuNode,
                                                   filterset_class=MenuFilter)
    menu_info = relay.Node.Field(MenuNode)
    menu_self_menus = List(MenuNode,
                           menu_type=Int(),
                           order_by=String(default_value='-create_time'))
Пример #2
0
class FinancialReportQuery(graphene.ObjectType):
    financial_report = graphene.Field(
        type=FinancialReport,
        description='Find a financial report using an ID',
        report_id=graphene.ID(
            required=True,
            description='The ID of a financial report',
        ),
    )
    financial_reports_by_company = filter.DjangoFilterConnectionField(
        type=FinancialReport,
        description=
        'Search for a list of financial report of a company (by the given UUID) that is ordered by date '
        'and time',
        filterset_class=FinancialReportFilter,
    )

    def resolve_financial_report(
        self,
        info: graphql.ResolveInfo,
        report_id: graphene.ID,
        **kwargs,
    ) -> FinancialReport:
        logging.debug(
            f'self={self}, info={info}, news_id={report_id} kwargs={kwargs}')
        return FinancialReportModel.objects.get(report_id=report_id, )
Пример #3
0
class RiskReportQuery(graphene.ObjectType):
    risk_report = graphene.Field(type=RiskReport,
                                 description='Find a risk report using an ID',
                                 report_id=graphene.ID(
                                     required=True,
                                     description='The ID of the risk report',
                                 ))
    risk_reports_by_company = filter.DjangoFilterConnectionField(
        type=RiskReport,
        description=
        'Search for a list of risk report of a company (by the given UUID) that is ordered by date and '
        'time',
        filterset_class=RiskReportFilter,
    )

    def resolve_risk_report(
        self,
        info: graphql.ResolveInfo,
        report_id: graphene.ID,
        **kwargs,
    ) -> RiskReport:
        logging.debug(
            f'self={self}, info={info}, report_id={report_id}, kwargs={kwargs}'
        )
        return RiskReportModel.objects.get(report_id=report_id, )
Пример #4
0
class Query(object):
    study = relay.Node.Field(StudyNode)
    line = relay.Node.Field(LineNode)
    assay = relay.Node.Field(AssayNode)
    measurement = relay.Node.Field(MeasurementNode)
    unit = relay.Node.Field(UnitNode)
    value = relay.Node.Field(MeasurementValueNode)

    all_studies = gfilter.DjangoFilterConnectionField(
        StudyNode,
        filterset_class=rest_views.StudyFilter,
    )
    all_lines = gfilter.DjangoFilterConnectionField(
        LineNode,
        filterset_class=rest_views.LineFilter,
    )
    all_assays = gfilter.DjangoFilterConnectionField(
        AssayNode,
        filterset_class=rest_views.AssayFilter,
    )
    all_measurements = gfilter.DjangoFilterConnectionField(
        MeasurementNode,
        filterset_class=rest_views.MeasurementFilter,
    )
    all_units = gfilter.DjangoFilterConnectionField(
        UnitNode,
        filterset_class=rest_views.MeasurementUnitFilter,
    )
    all_values = gfilter.DjangoFilterConnectionField(
        MeasurementValueNode,
        filterset_class=rest_views.MeasurementValueFilter,
    )
Пример #5
0
class CompanyQuery(graphene.ObjectType):
    company = graphene.Field(
        type=Company,
        description='Retrieve general information about a company using a UUID',
        company_id=graphene.UUID(
            required=True,
            description='The UUID of a company',
        ),
    )
    companies_by_name = filter.DjangoFilterConnectionField(
        type=Company,
        description='Search for companies that contains the given name',
        filterset_class=CompanyFilterByName,
    )
    companies_by_ratings = relay.ConnectionField(
        type=CompanyRatingConnection,
        description='Search for companies that matches the given ratings',
        ratings=graphene.List(
            of_type=graphene.NonNull(graphene.String),
            required=True,
        ),
    )

    def resolve_company(
        self,
        info: graphql.ResolveInfo,
        company_id: graphene.UUID,
        **kwargs,
    ) -> Company:
        logging.debug(f'self={self}, info={info}, kwargs={kwargs}')
        return CompanyModel.objects.get(company_id=company_id, )

    def resolve_companies_by_ratings(
        self,
        info: graphql.ResolveInfo,
        ratings: graphene.List,
        **kwargs,
    ) -> List[CompanyRating]:
        logging.debug(f'self={self}, info={info}, kwargs={kwargs}')
        companies: QuerySet = CompanyModel.objects.all()
        risk_reports: QuerySet = RiskReportModel.objects.all()
        results: List[CompanyRating] = []
        for company in companies:
            risk_report: RiskReportModel = risk_reports.filter(
                company_id=company.company_id).latest(field_name='date_time')
            if risk_report.risk_rating in ratings:
                results.append(
                    CompanyRating(company=company, risk_report=risk_report))
        return results
Пример #6
0
class Query:
    user = graphene.Field(types.UserType)
    token = graphene.Field(types.TokenType,
                           org_id=graphene.String(required=False))

    user_connections = graphene.List(types.ConnectionType,
                                     test=graphene.Boolean(required=False))
    system_connections = graphene.List(types.SystemConnectionType,
                                       test=graphene.Boolean(required=False))

    default_templates = types.generic.GenericScalar()
    address_templates = django_filter.DjangoFilterConnectionField(
        types.AddressTemplateType)
    customs_templates = django_filter.DjangoFilterConnectionField(
        types.CustomsTemplateType)
    parcel_templates = django_filter.DjangoFilterConnectionField(
        types.ParcelTemplateType)

    log = graphene.Field(types.LogType, id=graphene.Int(required=True))
    logs = django_filter.DjangoFilterConnectionField(
        types.LogType, filterset_class=types.LogFilter)
    shipments = django_filter.DjangoFilterConnectionField(types.ShipmentType)
    trackers = django_filter.DjangoFilterConnectionField(types.TrackerType)
    webhooks = django_filter.DjangoFilterConnectionField(types.WebhookType)

    @types.login_required
    def resolve_user(self, info):
        return types.User.objects.get(id=info.context.user.id)

    @types.login_required
    def resolve_token(self, info, **kwargs):
        return TokenSerializer.retrieve_token(info.context, **kwargs)

    @types.login_required
    def resolve_user_connections(self, info, **kwargs):
        connections = providers.Carrier.access_by(info.context).filter(
            created_by__isnull=False, **kwargs)
        return [connection.settings for connection in connections]

    @types.login_required
    def resolve_system_connections(self, info, **kwargs):
        return gateway.Carriers.list(context=info.context,
                                     system_only=True,
                                     **kwargs)

    @types.login_required
    def resolve_default_templates(self, info, **kwargs):
        templates = graph.Template.access_by(
            info.context).filter(is_default=True)
        return [
            serializers.DefaultTemplateSerializer(template).data
            for template in templates
        ]

    @types.login_required
    def resolve_address_templates(self, info, **kwargs):
        return graph.Template.access_by(
            info.context).filter(address__isnull=False)

    @types.login_required
    def resolve_customs_templates(self, info, **kwargs):
        return graph.Template.access_by(
            info.context).filter(customs__isnull=False)

    @types.login_required
    def resolve_parcel_templates(self, info, **kwargs):
        return graph.Template.access_by(
            info.context).filter(parcel__isnull=False)

    @types.login_required
    def resolve_log(self, info, **kwargs):
        return api.APILog.access_by(info.context).filter(**kwargs).first()

    @types.login_required
    def resolve_logs(self, info, **kwargs):
        return api.APILog.access_by(info.context)

    @types.login_required
    def resolve_shipments(self, info, **kwargs):
        return manager.Shipment.access_by(info.context)

    @types.login_required
    def resolve_trackers(self, info, **kwargs):
        return manager.Tracking.access_by(info.context)

    @types.login_required
    def resolve_webhooks(self, info, **kwargs):
        return events.Webhook.access_by(info.context)
Пример #7
0
class QueryType(graphene.AbstractType):
    album = relay.Node.Field(AlbumNode)
    albums = filter.DjangoFilterConnectionField(AlbumNode)
    track = relay.Node.Field(TrackNode)
    tracks = filter.DjangoFilterConnectionField(TrackNode)
Пример #8
0
class AuthedQuery(AbstractType, QueryResolver):
    user_refresh_token = jwt_relay.Refresh.Field()
    user_list = filter.DjangoFilterConnectionField(UserNode,
                                                   filterset_class=UserFilter)
    user_user_info = relay.Node.Field(UserNode)
    user_self_info = Field(UserNode)
Пример #9
0
class Query(graphene.ObjectType):
    """ Query entry point graphQL.
    """
    node = graphene.relay.Node.Field()

    # UTENTE LOGGATO
    user = graphene.Field(User)

    # SAMPLERANGES
    # all_sampleRanges = filter.DjangoFilterConnectionField(
    all_sampleRanges = DjangoConnectionField(
        SampleRange,
        startDate=graphene.String(),
        endDate=graphene.String(),
        description="all the sample range")
    sampleRange = graphene.Node.Field(SampleRange)

    # STRUCTURE
    all_structure = filter.DjangoFilterConnectionField(
        Structure, description="Filterable list of structure")
    structure = graphene.Node.Field(Structure)

    # NODO GENERICO
    node = graphene.Node.Field()

    # SETTINGS
    settings = filter.DjangoFilterConnectionField(
        Settings,
        filterset_class=SettingsFilter,
        description="Filterable settings values")
    setting = graphene.Node.Field(Settings)

    # WSP
    wsp = graphene.Field(
        Wsp,
        id=graphene.ID(),
    )

    # RANGE / Intevallo di rischio
    all_ranges = filter.DjangoFilterConnectionField(
        Range, description="List of all the ranges")
    rangenode = graphene.Node.Field(Range)

    chart = graphene.Field(
        ChartContainer,
        startDate=graphene.String(required=True),
        endDate=graphene.String(required=True),
        struct_type=graphene.String(),
        struct_id=graphene.ID(),
    )

    def resolve_wsp(self, info, **input):
        """ Questo resolve permette di recuperare un Wsp sia con global_id che
        con id del database.
        """
        genericService = GenericService()
        return genericService.Wsp(input=input)

    def resolve_chart(self, info, **input):
        chartContainer = ChartContainer(
            input.get('struct_type', None),
            input.get('startDate', None),
            input.get('endDate', None),
            input.get('struct_id', None),
        )
        return chartContainer

    # torno le informazioni dell'utente LOGGATO
    def resolve_user(self, info, **input):
        return info.context.user

    # torno i samplerange in ordine di data
    def resolve_all_sampleRanges(self, info, **input):
        genericService = GenericService()
        return genericService.allSampleRanges(input=input)

    def resolve_all_structure(self, info, **input):
        genericService = GenericService()
        return genericService.allStructure(input=input)