Skip to content

Commit

Permalink
feat: move QueryOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
theodu committed Aug 28, 2023
1 parent 5dac0e9 commit be721d0
Show file tree
Hide file tree
Showing 33 changed files with 83 additions and 289 deletions.
2 changes: 1 addition & 1 deletion src/kili/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import requests

from kili import __version__
from kili.core.graphql import QueryOptions
from kili.core.graphql.graphql_client import GraphQLClient, GraphQLClientName
from kili.core.graphql.operations.api_key.queries import APIKeyQuery, APIKeyWhere
from kili.core.graphql.operations.user.queries import GQL_ME
Expand Down Expand Up @@ -38,6 +37,7 @@
from kili.entrypoints.subscriptions.label import SubscriptionsLabel
from kili.exceptions import AuthenticationFailed, UserNotFoundError
from kili.gateways.kili_api_gateway import KiliAPIGateway
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.presentation.client.asset import AssetClientMethods
from kili.presentation.client.internal import InternalClientMethods
from kili.presentation.client.issue import IssueClientMethods
Expand Down
11 changes: 2 additions & 9 deletions src/kili/core/graphql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
"""GraphQL module."""

from abc import ABC, abstractmethod
from typing import Callable, Dict, Generator, List, NamedTuple, Optional, Type, TypeVar
from typing import Callable, Dict, Generator, List, Optional, Type, TypeVar

import requests
from typeguard import typechecked

from kili.core.constants import QUERY_BATCH_SIZE
from kili.core.helpers import format_result
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.utils.tqdm import tqdm

from .graphql_client import GraphQLClient

T = TypeVar("T")


class QueryOptions(NamedTuple):
"""Options when calling GraphQLQuery from the SDK."""

disable_tqdm: Optional[bool]
first: Optional[int] = None
skip: int = 0


class BaseQueryWhere(ABC):
"""Abtsract class for defining the where payload to send in a graphQL query."""

Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/list_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import pandas as pd
from tabulate import tabulate

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project.queries import ProjectQuery, ProjectWhere
from kili.entrypoints.cli.common_args import Options
from kili.entrypoints.cli.helpers import get_kili_client
from kili.gateways.kili_api_gateway.queries import QueryOptions


@click.command(name="list")
Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/member/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import click

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
Expand All @@ -18,6 +17,7 @@
collect_members_from_emails,
collect_members_from_project,
)
from kili.gateways.kili_api_gateway.queries import QueryOptions


# pylint: disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/member/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import requests

from kili.client import Kili
from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
)
from kili.entrypoints.cli.common_args import ROLES
from kili.entrypoints.cli.helpers import collect_from_csv
from kili.gateways.kili_api_gateway.queries import QueryOptions

REGEX_EMAIL = re.compile(r"([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+")

Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/member/list_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import pandas as pd
from tabulate import tabulate

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
)
from kili.entrypoints.cli.common_args import Arguments, Options
from kili.entrypoints.cli.helpers import get_kili_client
from kili.gateways.kili_api_gateway.queries import QueryOptions

ROLE_ORDER = {v: i for i, v in enumerate(["ADMIN", "TEAM_MANAGER", "REVIEWER", "LABELER"])}

Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/member/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import click

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
Expand All @@ -18,6 +17,7 @@
collect_members_from_emails,
collect_members_from_project,
)
from kili.gateways.kili_api_gateway.queries import QueryOptions


@click.command(name="rm")
Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/cli/project/member/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import click

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.project_user.queries import (
ProjectUserQuery,
ProjectUserWhere,
Expand All @@ -18,6 +17,7 @@
collect_members_from_emails,
collect_members_from_project,
)
from kili.gateways.kili_api_gateway.queries import QueryOptions


@click.command(name="update")
Expand Down
24 changes: 15 additions & 9 deletions src/kili/entrypoints/mutations/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from tenacity.wait import wait_exponential
from typeguard import typechecked

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.asset.queries import AssetQuery, AssetWhere
from kili.core.helpers import is_empty_list_with_warning
from kili.core.utils.pagination import mutate_from_paginated_call
from kili.entrypoints.base import BaseOperationEntrypointMixin
Expand All @@ -22,6 +20,9 @@
GQL_UPDATE_PROPERTIES_IN_ASSETS,
)
from kili.exceptions import MissingArgumentError
from kili.gateways.kili_api_gateway import KiliAPIGateway
from kili.gateways.kili_api_gateway.asset.types import AssetWhere
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.orm import Asset
from kili.services.asset_import import import_assets
from kili.services.asset_import_csv import get_text_assets_from_csv
Expand All @@ -36,6 +37,8 @@
class MutationsAsset(BaseOperationEntrypointMixin):
"""Set of Asset mutations."""

kili_api_gateway: KiliAPIGateway

# pylint: disable=too-many-arguments,too-many-locals
@typechecked
def append_many_to_dataset(
Expand Down Expand Up @@ -414,7 +417,8 @@ def verify_last_batch(last_batch: Dict, results: List) -> None:
return

asset_ids = last_batch["asset_ids"][-1:] # check last asset of the batch only
nb_assets_in_kili = AssetQuery(self.graphql_client, self.http_client).count(

nb_assets_in_kili = self.kili_api_gateway.count_assets(
AssetWhere(
project_id=project_id_,
asset_id_in=asset_ids,
Expand Down Expand Up @@ -490,7 +494,7 @@ def verify_last_batch(last_batch: Dict, results: List) -> None:
return

asset_ids = last_batch["asset_ids"][-1:] # check last asset of the batch only
nb_assets_in_review = AssetQuery(self.graphql_client, self.http_client).count(
nb_assets_in_review = self.kili_api_gateway.count_assets(
AssetWhere(
project_id=project_id_,
asset_id_in=asset_ids,
Expand All @@ -511,10 +515,11 @@ def verify_last_batch(last_batch: Dict, results: List) -> None:
# unlike send_back_to_queue, the add_to_review mutation doesn't always return the project ID
# it happens when no assets have been sent to review
if isinstance(result, dict) and "id" in result:
assets_in_review = AssetQuery(self.graphql_client, self.http_client)(
AssetWhere(project_id=result["id"], asset_id_in=asset_ids, status_in=["TO_REVIEW"]),
assets_in_review = self.kili_api_gateway.list_assets(
["id"],
AssetWhere(project_id=result["id"], asset_id_in=asset_ids, status_in=["TO_REVIEW"]),
QueryOptions(disable_tqdm=True),
None,
)
result["asset_ids"] = [asset["id"] for asset in assets_in_review]
return result
Expand Down Expand Up @@ -573,7 +578,7 @@ def verify_last_batch(last_batch: Dict, results: List) -> None:
return

asset_ids = last_batch["asset_ids"][-1:] # check lastest asset of the batch only
nb_assets_in_queue = AssetQuery(self.graphql_client, self.http_client).count(
nb_assets_in_queue = self.kili_api_gateway.count_assets(
AssetWhere(
project_id=project_id_,
asset_id_in=asset_ids,
Expand All @@ -592,10 +597,11 @@ def verify_last_batch(last_batch: Dict, results: List) -> None:
)
result = self.format_result("data", results[0])
if isinstance(result, dict) and "id" in result:
assets_in_queue = AssetQuery(self.graphql_client, self.http_client)(
AssetWhere(project_id=result["id"], asset_id_in=asset_ids, status_in=["ONGOING"]),
assets_in_queue = self.kili_api_gateway.list_assets(
["id"],
AssetWhere(project_id=result["id"], asset_id_in=asset_ids, status_in=["ONGOING"]),
QueryOptions(disable_tqdm=True),
None,
)
result["asset_ids"] = [asset["id"] for asset in assets_in_queue]
return result
2 changes: 1 addition & 1 deletion src/kili/entrypoints/mutations/data_connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typeguard import typechecked

from kili import services
from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.data_integration.queries import (
DataIntegrationsQuery,
DataIntegrationWhere,
)
from kili.entrypoints.base import BaseOperationEntrypointMixin
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.utils.logcontext import for_all_methods, log_call

from .queries import GQL_ADD_PROJECT_DATA_CONNECTION
Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/mutations/issue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

from typeguard import typechecked

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.label.queries import LabelQuery, LabelWhere
from kili.core.helpers import deprecate
from kili.entrypoints.base import BaseOperationEntrypointMixin
from kili.entrypoints.mutations.asset.helpers import get_asset_ids_or_throw_error
from kili.gateways.kili_api_gateway.issue.operations import GQL_CREATE_ISSUES
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.services.helpers import assert_all_arrays_have_same_size
from kili.utils.logcontext import for_all_methods, log_call

Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/mutations/issue/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from typing import List, Literal, cast

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.issue.queries import IssueQuery, IssueWhere
from kili.core.graphql.operations.label.queries import LabelQuery, LabelWhere
from kili.exceptions import NotFound
from kili.gateways.kili_api_gateway.queries import QueryOptions


# pylint: disable=missing-type-doc
Expand Down
2 changes: 1 addition & 1 deletion src/kili/entrypoints/queries/api_key/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from typeguard import typechecked

from kili.core.graphql import QueryOptions
from kili.core.graphql.operations.api_key.queries import APIKeyQuery, APIKeyWhere
from kili.entrypoints.base import BaseOperationEntrypointMixin
from kili.gateways.kili_api_gateway.queries import QueryOptions
from kili.presentation.client.common_validators import disable_tqdm_if_as_generator
from kili.utils.logcontext import for_all_methods, log_call

Expand Down
Loading

0 comments on commit be721d0

Please sign in to comment.