示例#1
0
文件: schema.py 项目: the-deep/server
class Query:
    analysis = DjangoObjectField(AnalysisType)
    analyses = DjangoPaginatedListObjectField(
        AnalysisListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    # Pillar
    analysis_pillar = DjangoObjectField(AnalysisPillarDetailType)
    analysis_pillars = DjangoPaginatedListObjectField(
        AnalysisPillarListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_analyses(root, info, **kwargs) -> QuerySet:
        return get_analysis_qs(info)

    @staticmethod
    def resolve_analysis_pillars(root, info, **kwargs) -> QuerySet:
        return get_analysis_pillar_qs(info)
示例#2
0
class Query:
    organization = DjangoObjectField(OrganizationType)
    organization_list = DjangoPaginatedListObjectField(
        OrganizationListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    organization_kind = DjangoObjectField(OrganizationKindObjectType)
    organization_kind_list = DjangoPaginatedListObjectField(
        OrganizationKindListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#3
0
class Query:
    resource = DjangoObjectField(ResourceType)
    resource_list = DjangoPaginatedListObjectField(
        ResourceListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    resource_group = DjangoObjectField(ResourceGroupType)
    resource_group_list = DjangoPaginatedListObjectField(
        ResourceGroupListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#4
0
class Query:
    contact = DjangoObjectField(ContactType)
    communication = DjangoObjectField(CommunicationType)
    contact_list = DjangoPaginatedListObjectField(
        ContactListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    communication_list = DjangoPaginatedListObjectField(
        CommunicationListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#5
0
class Query:
    lead = DjangoObjectField(LeadDetailType)
    leads = DjangoPaginatedListObjectField(
        LeadListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize', ))
    lead_group = DjangoObjectField(LeadGroupType)
    lead_groups = DjangoPaginatedListObjectField(
        LeadGroupListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    emm_entities = DjangoPaginatedListObjectField(
        EmmEntityListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    lead_emm_triggers = DjangoPaginatedListObjectField(
        LeadEmmTriggerListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    # TODO: Add Pagination
    emm_keywords = graphene.List(graphene.NonNull(EmmKeyWordType))
    emm_risk_factors = graphene.List(graphene.NonNull(EmmKeyRiskFactorType))

    @staticmethod
    def resolve_leads(root, info, **kwargs) -> QuerySet:
        return get_lead_qs(info)

    @staticmethod
    def resolve_lead_groups(root, info, **kwargs) -> QuerySet:
        return get_lead_group_qs(info)

    @staticmethod
    def resolve_emm_entities(root, info, **kwargs) -> QuerySet:
        return get_emm_entities_qs(info)

    @staticmethod
    def resolve_lead_emm_triggers(root, info, **kwargs) -> QuerySet:
        return get_lead_emm_entities_qs(info)

    @staticmethod
    def resolve_emm_keywords(root, info, **kwargs):
        return LeadEMMTrigger.objects.filter(
            lead__project=info.context.active_project).values(
                'emm_keyword').annotate(
                    total_count=models.Sum('count'),
                    key=models.F('emm_keyword'),
                    label=models.F('emm_keyword')).order_by('emm_keyword')

    @staticmethod
    def resolve_emm_risk_factors(root, info, **kwargs):
        return LeadEMMTrigger.objects.filter(
            ~models.Q(emm_risk_factor=''),
            ~models.Q(emm_risk_factor=None),
            lead__project=info.context.active_project,
        ).values('emm_risk_factor').annotate(
            total_count=models.Sum('count'),
            key=models.F('emm_risk_factor'),
            label=models.F('emm_risk_factor'),
        ).order_by('emm_risk_factor')
示例#6
0
class Query:
    figure = DjangoObjectField(FigureType)
    figure_list = DjangoPaginatedListObjectField(
        FigureListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    source_preview = DjangoObjectField(SourcePreviewType)
    entry = DjangoObjectField(EntryType)
    entry_list = DjangoPaginatedListObjectField(
        EntryListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#7
0
class AuthorNode(DjangoObjectType):
    entries = DjangoFilterPaginateListField(
        EntryNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'),
        filterset_class=EntryFilter)
    moderated_categories = DjangoFilterPaginateListField(
        CategoryNode, pagination=PageGraphqlPagination())

    class Meta:
        model = Author
        filter_fields = ['first_name', 'last_name']
示例#8
0
class BlogQuery(graphene.ObjectType):
    entries = DjangoFilterPaginateListField(
        EntryNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'),
        filterset_class=EntryFilter)
    authors = DjangoFilterPaginateListField(
        AuthorNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'))
    categories = DjangoFilterPaginateListField(
        CategoryNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'))

    debug = graphene.Field(DjangoDebug, name='__debug')
示例#9
0
文件: schema.py 项目: the-deep/server
class Query:
    project = DjangoObjectField(ProjectDetailType)
    projects = DjangoPaginatedListObjectField(
        ProjectListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    recent_projects = graphene.List(graphene.NonNull(ProjectDetailType))
    project_explore_stats = graphene.Field(ProjectExploreStatType)

    # only the region for which project are public
    projects_by_region = DjangoPaginatedListObjectField(
        ProjectByRegionListType)

    # PUBLIC NODES
    public_projects = DjangoPaginatedListObjectField(
        PublicProjectListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    public_projects_by_region = DjangoPaginatedListObjectField(
        PublicProjectByRegionListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    # NOTE: This is a custom feature, see https://github.com/the-deep/graphene-django-extras
    # see: https://github.com/eamigo86/graphene-django-extras/compare/graphene-v2...the-deep:graphene-v2

    @staticmethod
    def resolve_projects(root, info, **kwargs) -> QuerySet:
        return Project.get_for_gq(info.context.user).distinct()

    @staticmethod
    def resolve_recent_projects(root, info, **kwargs) -> QuerySet:
        # only the recent project of the user member of
        queryset = Project.get_for_gq(info.context.user, only_member=True)
        return Project.get_recent_active_projects(info.context.user, queryset)

    @staticmethod
    def resolve_projects_by_region(root, info, **kwargs):
        return Region.objects\
            .filter(centroid__isnull=False)\
            .order_by('centroid')

    @staticmethod
    def resolve_project_explore_stats(root, info, **kwargs):
        return info.context.dl.project.resolve_explore_stats()

    # PUBLIC RESOLVERS
    @staticmethod
    def resolve_public_projects(root, info, **kwargs) -> QuerySet:
        return PublicProjectListType.queryset()

    @staticmethod
    def resolve_public_projects_by_region(*args, **kwargs):
        return Query.resolve_projects_by_region(*args, **kwargs)
示例#10
0
class UserType(DjangoObjectType):
    class Meta:
        model = User
        exclude_fields = ('password',)

    review_entries = DjangoPaginatedListObjectField(EntryListType,
                                                    pagination=PageGraphqlPagination(
                                                        page_size_query_param='pageSize'
                                                    ), accessor='review_entries')
    created_entry = DjangoPaginatedListObjectField(EntryListType,
                                                   pagination=PageGraphqlPagination(
                                                       page_size_query_param='pageSize'
                                                   ), accessor='created_entry')
    role = Field(graphene.String)
示例#11
0
class Query:
    analysis_framework = DjangoObjectField(AnalysisFrameworkDetailType)
    analysis_frameworks = DjangoPaginatedListObjectField(
        AnalysisFrameworkListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
    public_analysis_frameworks = DjangoPaginatedListObjectField(
        PublicAnalysisFrameworkListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_analysis_frameworks(root, info, **kwargs) -> QuerySet:
        return AnalysisFramework.get_for_gq(info.context.user).distinct()

    @staticmethod
    def resolve_public_analysis_frameworks(root, info, **kwargs) -> QuerySet:
        return AnalysisFramework.objects.filter(is_private=False).distinct()
示例#12
0
文件: schema.py 项目: the-deep/server
class AnalysisPillarDetailType(AnalysisPillarType):
    class Meta:
        model = AnalysisPillar
        skip_registry = True
        only_fields = (
            'id',
            'title', 'main_statement', 'information_gap', 'assignee',
            'filters',
        )

    entries = DjangoPaginatedListObjectField(
        AnalysisPillarEntryListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_entries(root, info, **kwargs):
        # filtering out the entries whose lead published_on date is less than analysis end_date
        queryset = get_entry_qs(info).filter(
            project=root.analysis.project_id,
            lead__published_on__lte=root.analysis.end_date
        )
        discarded_entries_qs = DiscardedEntry.objects.filter(analysis_pillar=root).values('entry')
        if kwargs.get('discarded'):  # NOTE: From AnalysisPillarEntryGQFilterSet.discarded
            return queryset.filter(id__in=discarded_entries_qs)
        return queryset.exclude(id__in=discarded_entries_qs)
示例#13
0
class OrganizationType(DjangoObjectType):
    class Meta:
        model = Organization

    contacts = DjangoPaginatedListObjectField(
        ContactListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#14
0
class ResourceGroupType(DjangoObjectType):
    class Meta:
        model = ResourceGroup

    resources = DjangoPaginatedListObjectField(
        ResourceListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#15
0
class OrganizationKindObjectType(DjangoObjectType):
    class Meta:
        model = OrganizationKind

    organizations = DjangoPaginatedListObjectField(
        OrganizationListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#16
0
class EntryNode(DjangoObjectType):
    tags = DjangoFilterPaginateListField(
        TagNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'))

    class Meta:
        model = Entry
        filter_fields = ['title']
示例#17
0
class CrisisType(DjangoObjectType):
    class Meta:
        model = Crisis

    crisis_type = graphene.Field(CrisisTypeGrapheneEnum)
    events = DjangoPaginatedListObjectField(
        EventListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#18
0
文件: schema.py 项目: the-deep/server
class Query:
    entry = DjangoObjectField(EntryType)
    entries = DjangoPaginatedListObjectField(
        EntryListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_entries(root, info, **kwargs) -> QuerySet:
        return get_entry_qs(info)
示例#19
0
文件: schema.py 项目: the-deep/server
class Query:
    export = DjangoObjectField(UserExportType)
    exports = DjangoPaginatedListObjectField(
        UserExportListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_exports(root, info, **kwargs) -> QuerySet:
        return get_export_qs(info).filter(is_preview=False)
示例#20
0
class ContactType(DjangoObjectType):
    class Meta:
        model = Contact

    designation = graphene.Field(DesignationGrapheneEnum)
    gender = graphene.Field(GenderGrapheneEnum)
    communications = DjangoPaginatedListObjectField(
        CommunicationListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#21
0
文件: schema.py 项目: the-deep/server
class Query:
    region = DjangoObjectField(RegionDetailType)
    regions = DjangoPaginatedListObjectField(
        RegionListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_regions(root, info, **kwargs):
        return get_users_region_qs(info)
示例#22
0
class CategoryNode(DjangoObjectType):
    entries = DjangoFilterPaginateListField(
        EntryNode,
        pagination=PageGraphqlPagination(page_size_query_param='page_size'),
        filterset_class=EntryFilter)

    class Meta:
        model = Category
        filter_fields = ['name']
示例#23
0
class EntryType(DjangoObjectType):
    class Meta:
        model = Entry

    created_by = graphene.Field('apps.users.schema.UserType')
    last_modified_by = graphene.Field('apps.users.schema.UserType')
    figures = DjangoPaginatedListObjectField(
        FigureListType,
        pagination=PageGraphqlPagination(page_size_query_param='perPage'))
    reviewers = CustomDjangoListField('apps.users.schema.UserType')
    total_figures = graphene.Field(graphene.Int)
示例#24
0
class Query:
    assessment = DjangoObjectField(AssessmentType)
    assessments = DjangoPaginatedListObjectField(
        AssessmentListType,
        pagination=PageGraphqlPagination(
            page_size_query_param='pageSize'
        )
    )

    @staticmethod
    def resolve_assessments(root, info, **kwargs) -> QuerySet:
        return get_assessment_qs(info)
示例#25
0
class Query:
    me = graphene.Field(UserMeType)
    user = DjangoObjectField(UserType)
    users = DjangoPaginatedListObjectField(
        UserListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    @staticmethod
    def resolve_me(root, info, **kwargs) -> Union[User, None]:
        if info.context.user.is_authenticated:
            return info.context.user
        return None
示例#26
0
文件: schema.py 项目: zayer60/graphql
class Query(graphene.ObjectType):
    all_ingredients = DjangoFilterPaginateListField(
        IngredientType, pagination=PageGraphqlPagination())
    get_category = graphene.Field(CategoryType,
                                  name=graphene.String(required=True))

    def resolve_all_ingredients(root, info):
        return Ingredient.objects.select_related("category").all()

    def resolve_get_category(root, info, name):
        try:
            return Category.objects.get(name=name)
        except Category.DoesNotExist:
            return None
示例#27
0
class Query:
    trigger_list = DjangoFilterListField(TriggerType)
    sub_type_trigger_list = DjangoFilterListField(TriggerSubObjectType)
    violence_list = DjangoFilterListField(ViolenceType)
    actor_list = DjangoFilterListField(ActorType)
    disaster_category_list = DjangoFilterListField(DisasterCategoryType)
    disaster_sub_category_list = DjangoFilterListField(DisasterSubCategoryType)
    disaster_type_list = DjangoFilterListField(DisasterTypeObjectType)
    disaster_sub_type_list = DjangoFilterListField(DisasterSubObjectType)

    event = DjangoObjectField(EventType)
    event_list = DjangoPaginatedListObjectField(
        EventListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))
示例#28
0
class Query:
    organization = DjangoObjectField(OrganizationType)
    organizations = DjangoPaginatedListObjectField(
        OrganizationListType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))
    public_organizations = DjangoPaginatedListObjectField(
        PublicOrganizationListObjectType,
        pagination=NoOrderingPageGraphqlPagination(
            page_size_query_param='pageSize'))
    organization_type = DjangoObjectField(OrganizationTypeType)
    organization_types = DjangoPaginatedListObjectField(
        OrganizationTypeListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))

    def resolve_organizations(root, info, **kwargs):
        # Filterout merged organizations
        return Organization.objects.filter(parent__isnull=True).all()
示例#29
0
class CountryType(DjangoObjectType):
    class Meta:
        model = Country

    last_summary = graphene.Field(SummaryType)
    last_contextual_update = graphene.Field(ContextualUpdateType)
    contacts = DjangoPaginatedListObjectField(
        ContactListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='contacts')
    operating_contacts = DjangoPaginatedListObjectField(
        ContactListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='operating_contacts')
    contextual_updates = DjangoPaginatedListObjectField(
        ContextualUpdateListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='contextual_updates')
    summaries = DjangoPaginatedListObjectField(
        SummaryListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='summaries')
    crises = graphene.Dynamic(lambda: DjangoPaginatedListObjectField(
        get_type('apps.crisis.schema.CrisisListType'),
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='crises'))
    entries = graphene.Dynamic(lambda: DjangoPaginatedListObjectField(
        get_type('apps.entry.schema.EntryListType'),
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'),
        accessor='entries'))

    @staticmethod
    def get_queryset(queryset, info):
        # graphene_django/fields.py:57 demands we implement this method
        # so that we can filter based on request, but we do not need
        return queryset
示例#30
0
class Query:
    crisis = DjangoObjectField(CrisisType)
    crisis_list = DjangoPaginatedListObjectField(
        CrisisListType,
        pagination=PageGraphqlPagination(page_size_query_param='pageSize'))