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

[V8] Implement graph.query #43

Open
wants to merge 1 commit into
base: v8/develop
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions dkg/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from dkg.manager import DefaultRequestManager
from dkg.method import Method
from dkg.module import Module
from dkg.types import NQuads
from dkg.types import NQuads, GraphState, GraphLocation, UAL
from dkg.utils.decorators import retry
from dkg.utils.node_request import NodeRequest, validate_operation_status

Expand All @@ -37,14 +37,20 @@ def __init__(self, manager: DefaultRequestManager):
def query(
self,
query: str,
repository: str,
graphState: GraphState = GraphState.CURRENT,
graphLocation: GraphLocation = GraphLocation.PUBLIC,
paranetUAL: UAL = "",
) -> NQuads:
parsed_query = parseQuery(query)
query_type = parsed_query[1].name.replace("Query", "").upper()

operation_id: NodeResponseDict = self._query(query, query_type, repository)[
"operationId"
]
operation_id: NodeResponseDict = self._query(
query,
query_type,
graphState,
graphLocation,
paranetUAL,
)["operationId"]
operation_result = self.get_operation_result(operation_id, "query")

return operation_result["data"]
Expand Down
2 changes: 1 addition & 1 deletion dkg/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
AgreementData,
Environment,
)
from .dkg_node import UAL # NOQA: F401
from .dkg_node import UAL, GraphState, GraphLocation # NOQA: F401
from .encoding import BytesLike, DataHexStr, HexStr # NOQA: F401
from .evm import Address, ChecksumAddress, Wei # NOQA: F401
from .generics import TFunc, TReturn # NOQA: F401
Expand Down
15 changes: 15 additions & 0 deletions dkg/types/dkg_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@
# under the License.

from typing import NewType
from enum import Enum

UAL = NewType("UAL", str)

class GraphLocation(str, Enum):
PUBLIC = 'PUBLIC_KG'
PRIVATE = 'LOCAL_KG'

def __str__(self) -> str:
return self.value

class GraphState(str, Enum):
CURRENT = 'CURRENT'
HISTORICAL = 'HISTORICAL'

def __str__(self) -> str:
return self.value
10 changes: 8 additions & 2 deletions dkg/utils/node_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from dkg.dataclasses import BidSuggestionRange, HTTPRequestMethod
from dkg.exceptions import OperationFailed, OperationNotFinished
from dkg.types import AutoStrEnumUpperCase, UAL, Address, DataHexStr, NQuads
from dkg.types import AutoStrEnumUpperCase, UAL, Address, DataHexStr, NQuads, GraphState, GraphLocation


@dataclass
Expand Down Expand Up @@ -77,7 +77,13 @@ class NodeRequest:
query = NodeCall(
method=HTTPRequestMethod.POST,
path="query",
data={"query": str, "type": str, "repository": str},
data={
"query": str,
"type": str,
"graphState": GraphState,
"graphLocation": GraphLocation,
"paranetUAL": UAL,
},
)


Expand Down