Skip to content

Commit

Permalink
Implemented ReverseDirectRelationConnection (#1540)
Browse files Browse the repository at this point in the history
Co-authored-by: Per Arne Tollefsen <[email protected]>
Co-authored-by: erlendvollset <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent a7a1685 commit 487dc72
Show file tree
Hide file tree
Showing 8 changed files with 471 additions and 89 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.7.0] - 2023-12-20
### Added
- Support for `ViewProperty` types `SingleReverseDirectRelation` and `MultiReverseDirectRelation` in data modeling.

## [7.6.0] - 2023-12-13
### Added
- Support for querying data models through graphql. See `client.data_modeling.graphql.query`.
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.6.0"
__version__ = "7.7.0"
__api_subversion__ = "V20220125"
2 changes: 2 additions & 0 deletions cognite/client/data_classes/data_modeling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
DataModelingId,
EdgeId,
NodeId,
PropertyId,
VersionedDataModelingId,
ViewId,
ViewIdentifier,
Expand Down Expand Up @@ -98,6 +99,7 @@
"ViewIdentifier",
"ViewApply",
"ViewApplyList",
"PropertyId",
"MappedPropertyApply",
"VersionedDataModelingId",
"DataModelingId",
Expand Down
35 changes: 34 additions & 1 deletion cognite/client/data_classes/data_modeling/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

from abc import ABC
from dataclasses import asdict, dataclass, field
from typing import Any, ClassVar, Literal, Protocol, Sequence, Tuple, TypeVar, Union, cast
from typing import TYPE_CHECKING, Any, ClassVar, Literal, Protocol, Sequence, Tuple, TypeVar, Union, cast

from typing_extensions import Self

from cognite.client.data_classes._base import CogniteObject
from cognite.client.utils._auxiliary import rename_and_exclude_keys
from cognite.client.utils._identifier import DataModelingIdentifier, DataModelingIdentifierSequence
from cognite.client.utils._text import convert_all_keys_recursive, convert_all_keys_to_snake_case
from cognite.client.utils.useful_types import SequenceNotStr

if TYPE_CHECKING:
from cognite.client import CogniteClient


@dataclass(frozen=True)
class AbstractDataclass(ABC):
Expand Down Expand Up @@ -138,6 +144,33 @@ def as_property_ref(self, property: str) -> tuple[str, ...]:
return (self.space, self.as_source_identifier(), property)


@dataclass(frozen=True)
class PropertyId(CogniteObject):
source: ViewId | ContainerId
property: str

@classmethod
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
return cls(
source=cls.__load_view_or_container_id(resource["source"]),
property=resource["identifier"],
)

@staticmethod
def __load_view_or_container_id(view_or_container_id: dict[str, Any]) -> ViewId | ContainerId:
if "type" in view_or_container_id and view_or_container_id["type"] in {"view", "container"}:
if view_or_container_id["type"] == "view":
return ViewId.load(view_or_container_id)
return ContainerId.load(view_or_container_id)
raise ValueError(f"Invalid type {view_or_container_id}")

def dump(self, camel_case: bool = True) -> dict[str, Any]:
return {
"source": self.source.dump(camel_case=camel_case, include_type=True),
"identifier": self.property,
}


@dataclass(frozen=True)
class DataModelId(VersionedDataModelingId):
_type = "datamodel"
Expand Down
Loading

0 comments on commit 487dc72

Please sign in to comment.