aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/graph/graph.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsfs/graph/graph.py')
-rw-r--r--bsfs/graph/graph.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/bsfs/graph/graph.py b/bsfs/graph/graph.py
index 51fe75d..f030fed 100644
--- a/bsfs/graph/graph.py
+++ b/bsfs/graph/graph.py
@@ -9,13 +9,15 @@ import os
import typing
# bsfs imports
-from bsfs.query import ast
+from bsfs.query import ast, validate
from bsfs.schema import Schema
from bsfs.triple_store import TripleStoreBase
from bsfs.utils import URI, typename
# inner-module imports
+from . import ac
from . import nodes as _nodes
+from . import resolve
# exports
__all__: typing.Sequence[str] = (
@@ -44,6 +46,9 @@ class Graph():
def __init__(self, backend: TripleStoreBase, user: URI):
self._backend = backend
self._user = user
+ self._resolver = resolve.Filter(self._backend.schema)
+ self._validate = validate.Filter(self._backend.schema)
+ self._ac = ac.NullAC(self._backend, self._user)
# ensure Graph schema requirements
self.migrate(self._backend.schema)
@@ -85,6 +90,9 @@ class Graph():
# migrate schema in backend
# FIXME: consult access controls!
self._backend.schema = schema
+ # re-initialize members
+ self._resolver.schema = self.schema
+ self._validate.schema = self.schema
# return self
return self
@@ -108,11 +116,21 @@ class Graph():
*node_type*) once some data is assigned to them.
"""
- type_ = self.schema.node(node_type)
- return _nodes.Nodes(self._backend, self._user, type_, {guid})
+ return self.nodes(node_type, {guid})
- def get(self, node_type: URI, subject: ast.filter.FilterExpression) -> _nodes.Nodes:
+ def get(self, node_type: URI, query: ast.filter.FilterExpression) -> _nodes.Nodes: # FIXME: How about empty query?
"""Return a `Nodes` instance over all nodes of type *node_type* that match the *subject* query."""
- raise NotImplementedError()
+ # get node type
+ type_ = self.schema.node(node_type)
+ # resolve Nodes instances
+ query = self._resolver(type_, query)
+ # add access controls to query
+ query = self._ac.filter_read(type_, query)
+ # validate query
+ self._validate(type_, query)
+ # query the backend
+ guids = self._backend.get(type_, query) # no need to materialize
+ # return Nodes instance
+ return _nodes.Nodes(self._backend, self._user, type_, guids)
## EOF ##