Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/resolvers.py
Show All 10 Lines | |||||
# and in the following priority order | # and in the following priority order | ||||
# - In this module using a decorator (eg: @visitstatus.field("snapshot") | # - In this module using a decorator (eg: @visitstatus.field("snapshot") | ||||
# Every object (type) is expected to resolve this way as they can accept arguments | # Every object (type) is expected to resolve this way as they can accept arguments | ||||
# eg: origin.visits takes arguments to paginate | # eg: origin.visits takes arguments to paginate | ||||
# - As a property in the Node object (eg: resolvers.visit.BaseVisitNode.id) | # - As a property in the Node object (eg: resolvers.visit.BaseVisitNode.id) | ||||
# Every scalar is expected to resolve this way | # Every scalar is expected to resolve this way | ||||
# - As an attribute/item in the object/dict returned by a backend (eg: Origin.url) | # - As an attribute/item in the object/dict returned by a backend (eg: Origin.url) | ||||
from typing import Optional | |||||
from ariadne import ObjectType, UnionType | from ariadne import ObjectType, UnionType | ||||
from graphql.type import GraphQLResolveInfo | from graphql.type import GraphQLResolveInfo | ||||
from swh.graphql import resolvers as rs | from swh.graphql import resolvers as rs | ||||
from swh.graphql.utils import utils | from swh.graphql.utils import utils | ||||
from .resolver_factory import get_connection_resolver, get_node_resolver | from .resolver_factory import get_connection_resolver, get_node_resolver | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
) -> rs.snapshot.SnapshotNode: | ) -> rs.snapshot.SnapshotNode: | ||||
""" """ | """ """ | ||||
resolver = get_node_resolver("snapshot") | resolver = get_node_resolver("snapshot") | ||||
return resolver(obj, info, **kw) | return resolver(obj, info, **kw) | ||||
@visit_status.field("snapshot") | @visit_status.field("snapshot") | ||||
def visit_snapshot_resolver( | def visit_snapshot_resolver( | ||||
obj, info: GraphQLResolveInfo, **kw | obj: rs.visit_status.BaseVisitStatusNode, info: GraphQLResolveInfo, **kw | ||||
) -> rs.snapshot.VisitSnapshotNode: | ) -> Optional[rs.snapshot.VisitSnapshotNode]: | ||||
if obj.snapshotSWHID is None: | |||||
return None | |||||
resolver = get_node_resolver("visit-snapshot") | resolver = get_node_resolver("visit-snapshot") | ||||
return resolver(obj, info, **kw) | return resolver(obj, info, **kw) | ||||
@snapshot_branch.field("target") | @snapshot_branch.field("target") | ||||
def snapshot_branch_target_resolver( | def snapshot_branch_target_resolver( | ||||
obj: rs.snapshot_branch.BaseSnapshotBranchNode, info: GraphQLResolveInfo, **kw | obj: rs.snapshot_branch.BaseSnapshotBranchNode, info: GraphQLResolveInfo, **kw | ||||
): | ): | ||||
▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines |