Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: issues query #1501

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/kili/adapters/kili_api_gateway/issue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
"""Mixin extending Kili API Gateway class with Issue related operations."""

from typing import List
from typing import Dict, Generator, List

from kili.adapters.kili_api_gateway.base import BaseOperationMixin
from kili.adapters.kili_api_gateway.issue.mappers import issue_where_mapper
from kili.adapters.kili_api_gateway.helpers.queries import (
PaginatedGraphQLQuery,
QueryOptions,
fragment_builder,
)
from kili.adapters.kili_api_gateway.issue.operations import (
GQL_COUNT_ISSUES,
GQL_CREATE_ISSUES,
)
from kili.adapters.kili_api_gateway.issue.types import IssueToCreateKiliAPIGatewayInput
from kili.core.utils.pagination import BatchIteratorBuilder
from kili.domain.issue import IssueFilters, IssueId, IssueType
from kili.domain.types import ListOrTuple
from kili.utils import tqdm

from .mappers import issue_where_mapper
from .operations import get_issues_query


class IssueOperationMixin(BaseOperationMixin):
"""GraphQL Mixin extending GraphQL Gateway class with Issue related operations."""
Expand Down Expand Up @@ -53,3 +60,14 @@ def count_issues(self, filters: IssueFilters) -> int:
payload = {"where": where}
count_result = self.graphql_client.execute(GQL_COUNT_ISSUES, payload)
return count_result["data"]

def list_issues(
self, filters: IssueFilters, fields: ListOrTuple[str], options: QueryOptions
) -> Generator[Dict, None, None]:
"""Send a GraphQL request calling issues resolver."""
fragment = fragment_builder(fields)
query = get_issues_query(fragment)
where = issue_where_mapper(filters=filters)
return PaginatedGraphQLQuery(self.graphql_client).execute_query_from_paginated_call(
query, where, options, "Retrieving issues", GQL_COUNT_ISSUES
)
4 changes: 3 additions & 1 deletion src/kili/adapters/kili_api_gateway/issue/mappers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""GraphQL payload data mappers for asset operations."""

from typing import Any, Dict

from kili.domain.issue import IssueFilters


def issue_where_mapper(filters: IssueFilters):
def issue_where_mapper(filters: IssueFilters) -> Dict[str, Any]:
"""Build the GraphQL IssueWhere variable to be sent in an operation."""
return {
"project": {"id": filters.project_id},
Expand Down
11 changes: 11 additions & 0 deletions src/kili/adapters/kili_api_gateway/issue/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@
data: countIssues(where: $where)
}
"""


def get_issues_query(fragment: str) -> str:
"""Return the GraphQL issues query."""
return f"""
query issues($where: IssueWhere!, $first: PageSize!, $skip: Int!) {{
data: issues(where: $where, first: $first, skip: $skip) {{
{fragment}
}}
}}
"""
2 changes: 0 additions & 2 deletions src/kili/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from kili.entrypoints.mutations.user import MutationsUser
from kili.entrypoints.queries.data_connection import QueriesDataConnection
from kili.entrypoints.queries.data_integration import QueriesDataIntegration
from kili.entrypoints.queries.issue import QueriesIssue
from kili.entrypoints.queries.label import QueriesLabel
from kili.entrypoints.queries.notification import QueriesNotification
from kili.entrypoints.queries.organization import QueriesOrganization
Expand Down Expand Up @@ -65,7 +64,6 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes
MutationsUser,
QueriesDataConnection,
QueriesDataIntegration,
QueriesIssue,
QueriesLabel,
QueriesNotification,
QueriesOrganization,
Expand Down
Empty file.
56 changes: 0 additions & 56 deletions src/kili/core/graphql/operations/issue/queries.py

This file was deleted.

4 changes: 3 additions & 1 deletion src/kili/domain/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from dataclasses import dataclass
from typing import List, Literal, NewType, Optional

from kili.domain.project import ProjectId

IssueType = Literal["ISSUE", "QUESTION"]
IssueStatus = Literal["OPEN", "SOLVED"]
IssueId = NewType("IssueId", str)
Expand All @@ -11,7 +13,7 @@
class IssueFilters:
"""Issue filters for running an issue search."""

project_id: str
project_id: ProjectId
asset_id: Optional[str] = None
asset_id_in: Optional[List[str]] = None
issue_type: Optional[IssueType] = None
Expand Down
163 changes: 0 additions & 163 deletions src/kili/entrypoints/queries/issue/__init__.py

This file was deleted.

11 changes: 5 additions & 6 deletions src/kili/presentation/client/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from typeguard import typechecked

from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
from kili.domain.asset import AssetFilters
from kili.domain.issue import IssueStatus, IssueType
from kili.domain.types import ListOrTuple
Expand Down Expand Up @@ -437,12 +438,10 @@ def assets(
assets_gen = asset_use_cases.list_assets(
filters,
fields,
first,
skip,
disable_tqdm,
download_media,
local_media_dir,
label_output_format,
download_media=download_media,
local_media_dir=local_media_dir,
label_output_format=label_output_format,
options=QueryOptions(disable_tqdm=disable_tqdm, first=first, skip=skip),
)

if format == "pandas":
Expand Down
5 changes: 4 additions & 1 deletion src/kili/presentation/client/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typeguard import typechecked

from kili.adapters.kili_api_gateway import KiliAPIGateway
from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions
from kili.domain.api_key import ApiKeyFilters
from kili.domain.types import ListOrTuple
from kili.entrypoints.mutations.organization import MutationsOrganization
Expand Down Expand Up @@ -96,7 +97,9 @@ def api_keys(
"""
api_key_use_cases = ApiKeyUseCases(self.kili_api_gateway)
filters = ApiKeyFilters(api_key_id=api_key_id, user_id=user_id, api_key=api_key)
api_keys_gen = api_key_use_cases.list_api_keys(filters, fields, first, skip, disable_tqdm)
api_keys_gen = api_key_use_cases.list_api_keys(
filters, fields, QueryOptions(first=first, skip=skip, disable_tqdm=disable_tqdm)
)

if as_generator:
return api_keys_gen
Expand Down
Loading