Exemple #1
0
    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)
Exemple #2
0
    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()
Exemple #3
0
def test_video():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.video)
Exemple #4
0
def test_repository():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.dataset.repository)
Exemple #5
0
def test_user():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.user)
Exemple #6
0
def test_project():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.project)
Exemple #7
0
def test_paginated_frames():
    # frame_search returns PaginatedFrames
    op = Operation(Query)
    FieldsManager.select_default_fields(op.frame_search)
Exemple #8
0
def test_label_set():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.label_set)
Exemple #9
0
def test_image():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.image)
Exemple #10
0
def test_group():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.group)
Exemple #11
0
def test_frames():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.frames)
Exemple #12
0
def test_dataset_frame():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.dataset_frame)
Exemple #13
0
def test_collection():
    op = Operation(Query)
    FieldsManager.select_default_fields(op.collection)
Exemple #14
0
def test_enum():
    # AnnotationImportState is an Enum.
    op = Operation(Query)
    FieldsManager.select_default_fields(op.image.annotation_import_state)
Exemple #15
0
def test_scalar():
    # collections_query_count returns an Int, which is a Scalar.
    op = Operation(Query)
    FieldsManager.select_default_fields(op.collections_query_count)