Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/base_node.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from abc import ABC | from abc import ABC | ||||
from collections import namedtuple | from collections import namedtuple | ||||
from swh.graphql.errors import ObjectNotFoundError | from swh.graphql.errors import ObjectNotFoundError | ||||
class BaseNode(ABC): | class BaseNode(ABC): | ||||
""" | """ | ||||
Base class for all the Node resolvers | Base resolver for all the nodes | ||||
""" | """ | ||||
def __init__(self, obj, info, node_data=None, **kwargs): | def __init__(self, obj, info, node_data=None, **kwargs): | ||||
self.obj = obj | self.obj = obj | ||||
self.info = info | self.info = info | ||||
self.kwargs = kwargs | self.kwargs = kwargs | ||||
self._node = self._get_node(node_data) | self._node = self._get_node(node_data) | ||||
# handle the errors, if any, after _node is set | # handle the errors, if any, after _node is set | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def __getattr__(self, name): | ||||
""" | """ | ||||
return getattr(self._node, name) | return getattr(self._node, name) | ||||
def is_type_of(self): | def is_type_of(self): | ||||
return self.__class__.__name__ | return self.__class__.__name__ | ||||
class BaseSWHNode(BaseNode): | class BaseSWHNode(BaseNode): | ||||
""" | |||||
Base resolver for all the nodes with a SWHID field | |||||
""" | |||||
@property | @property | ||||
def swhid(self): | def swhid(self): | ||||
return self._node.swhid() | return self._node.swhid() |