-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: theodu <[email protected]>
- Loading branch information
Showing
24 changed files
with
304 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# Issue module | ||
|
||
## Queries | ||
::: kili.presentation.client.issue.IssueClientMethods | ||
::: kili.entrypoints.queries.issue.__init__.QueriesIssue | ||
|
||
## Mutations | ||
::: kili.entrypoints.mutations.issue.__init__.MutationsIssue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Issue domain.""" | ||
from dataclasses import dataclass | ||
from typing import Literal | ||
|
||
IssueType = Literal["ISSUE", "QUESTION"] | ||
IssueStatus = Literal["OPEN", "SOLVED"] | ||
|
||
|
||
@dataclass | ||
class Issue: | ||
"""Issue Entity.""" | ||
|
||
id_: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Kili API Gateway module for interacting with Kili.""" | ||
import requests | ||
|
||
from kili.core.graphql.graphql_client import GraphQLClient | ||
from kili.gateways.kili_api_gateway.issue import IssueOperationMixin | ||
|
||
|
||
class KiliAPIGateway(IssueOperationMixin): | ||
"""GraphQL gateway to communicate with Kili backend.""" | ||
|
||
def __init__(self, graphql_client: GraphQLClient, http_client: requests.Session): | ||
self.graphql_client = graphql_client | ||
self.http_client = http_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Mixin extending Kili API Gateway class with Issue related operations.""" | ||
|
||
from typing import List, Optional | ||
|
||
from kili.core.graphql.graphql_client import GraphQLClient | ||
from kili.core.utils.pagination import BatchIteratorBuilder | ||
from kili.domain.issue import Issue, IssueStatus, IssueType | ||
from kili.gateways.kili_api_gateway.issue.operations import ( | ||
GQL_COUNT_ISSUES, | ||
GQL_CREATE_ISSUES, | ||
) | ||
from kili.gateways.kili_api_gateway.issue.types import ( | ||
IssueToCreateKiliAPIGatewayInput, | ||
IssueWhere, | ||
) | ||
from kili.utils import tqdm | ||
|
||
|
||
class IssueOperationMixin: | ||
"""GraphQL Mixin extending GraphQL Gateway class with Issue related operations.""" | ||
|
||
graphql_client: GraphQLClient | ||
|
||
def create_issues( | ||
self, type_: IssueType, issues: List[IssueToCreateKiliAPIGatewayInput] | ||
) -> List[Issue]: | ||
"""Send a GraphQL request calling createIssues resolver.""" | ||
created_issue_entities: List[Issue] = [] | ||
with tqdm.tqdm(total=len(issues)) as pbar: | ||
for issues_batch in BatchIteratorBuilder(issues): | ||
batch_targeted_asset_ids = [issue.asset_id for issue in issues_batch] | ||
payload = { | ||
"issues": [ | ||
{ | ||
"issueNumber": 0, | ||
"labelID": issue.label_id, | ||
"objectMid": issue.object_mid, | ||
"type": type_, | ||
"assetId": issue.asset_id, | ||
"text": issue.text, | ||
} | ||
for issue in issues_batch | ||
], | ||
"where": {"idIn": batch_targeted_asset_ids}, | ||
} | ||
result = self.graphql_client.execute(GQL_CREATE_ISSUES, payload) | ||
batch_created_issues = result["data"] | ||
created_issue_entities.extend( | ||
[Issue(id_=issue["id"]) for issue in batch_created_issues] | ||
) | ||
pbar.update(len(issues_batch)) | ||
return created_issue_entities | ||
|
||
def count_issues( # pylint: disable=too-many-arguments, | ||
self, | ||
project_id: str, | ||
asset_id: Optional[str] = None, | ||
asset_id_in: Optional[List[str]] = None, | ||
issue_type: Optional[IssueType] = None, | ||
status: Optional[IssueStatus] = None, | ||
) -> int: | ||
"""Send a GraphQL request calling countIssues resolver.""" | ||
where = IssueWhere(project_id, asset_id, asset_id_in, issue_type, status) | ||
payload = { | ||
"where": where.get_graphql_where_value(), | ||
} | ||
count_result = self.graphql_client.execute(GQL_COUNT_ISSUES, payload) | ||
return count_result["data"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""GraphQL Issues operations.""" | ||
|
||
GQL_CREATE_ISSUES = """ | ||
mutation createIssues( | ||
$issues: [IssueToCreate!]! | ||
$where: AssetWhere! | ||
) { | ||
data: createIssues( | ||
issues: $issues | ||
where: $where | ||
) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
GQL_COUNT_ISSUES = """ | ||
query countIssues($where: IssueWhere!) { | ||
data: countIssues(where: $where) | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Types for the Issue-related Kili API gateway functions.""" | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
from kili.domain.issue import IssueStatus, IssueType | ||
|
||
|
||
@dataclass | ||
class IssueToCreateKiliAPIGatewayInput: | ||
"""Data about an issue to create needed in graphql createIssue resolver.""" | ||
|
||
label_id: Optional[str] | ||
object_mid: Optional[str] | ||
asset_id: str | ||
text: Optional[str] | ||
|
||
|
||
@dataclass | ||
class IssueWhere: | ||
"""Tuple to be passed to the IssueQuery to restrict query.""" | ||
|
||
project_id: str | ||
asset_id: Optional[str] = None | ||
asset_id_in: Optional[List[str]] = None | ||
issue_type: Optional[IssueType] = None | ||
status: Optional[IssueStatus] = None | ||
|
||
def get_graphql_where_value(self): | ||
"""Build the GraphQL IssueWhere variable value to be sent in an operation.""" | ||
return { | ||
"project": {"id": self.project_id}, | ||
"asset": {"id": self.asset_id}, | ||
"assetIn": self.asset_id_in, | ||
"status": self.status, | ||
"type": self.issue_type, | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.