def prepare_query(self, query_selector): # TODO: account for exclusions in default fields for excluded in self.excluded: self.paths[excluded] = False # start by adding all requested fields all_selectors = [] for path, value in self.paths.items(): if value is False or value is None: # excluded field continue field = self.get_attr_by_path(path, query_selector) all_selectors.append((path, field)) if value is True: field() if isinstance(value, dict): field(**value) # selectors that dont have any child nodes call them # this is not a smart way of doing this leaf_selectors = [] for path, selector in all_selectors: # a selector is a leaf if no other selectors are # included below it for other_path, _ in all_selectors: if is_subfield_of(path, other_path): # has a subfield selector--not a leaf break else: # no leaf found leaf_selectors.append(selector) # if no fields are selected, select defaults on query if len(leaf_selectors) == 0: leaf_selectors.append(query_selector) # add default fields to all leafs: for leaf in leaf_selectors: FieldsManager.select_default_fields(leaf)
def __init__(self, config): self.config = config self.email = None self.graphql_url = ConservatorConnection.to_graphql_url(config.url) python_ver = sys.version.split()[0] os_name = platform.system() os_ver = platform.release() agent_string = ( f"conservator-cli/{cli_ver} Python/{python_ver} {os_name}/{os_ver}" ) headers = { "authorization": config.key, "User-Agent": agent_string, } self.endpoint = HTTPEndpoint(self.graphql_url, base_headers=headers) self.fields_manager = FieldsManager()
def test_video(): op = Operation(Query) FieldsManager.select_default_fields(op.video)
def test_repository(): op = Operation(Query) FieldsManager.select_default_fields(op.dataset.repository)
def test_user(): op = Operation(Query) FieldsManager.select_default_fields(op.user)
def test_project(): op = Operation(Query) FieldsManager.select_default_fields(op.project)
def test_paginated_frames(): # frame_search returns PaginatedFrames op = Operation(Query) FieldsManager.select_default_fields(op.frame_search)
def test_label_set(): op = Operation(Query) FieldsManager.select_default_fields(op.label_set)
def test_image(): op = Operation(Query) FieldsManager.select_default_fields(op.image)
def test_group(): op = Operation(Query) FieldsManager.select_default_fields(op.group)
def test_frames(): op = Operation(Query) FieldsManager.select_default_fields(op.frames)
def test_dataset_frame(): op = Operation(Query) FieldsManager.select_default_fields(op.dataset_frame)
def test_collection(): op = Operation(Query) FieldsManager.select_default_fields(op.collection)
def test_enum(): # AnnotationImportState is an Enum. op = Operation(Query) FieldsManager.select_default_fields(op.image.annotation_import_state)
def test_scalar(): # collections_query_count returns an Int, which is a Scalar. op = Operation(Query) FieldsManager.select_default_fields(op.collections_query_count)