Ejemplo n.º 1
0
 def __init__(self, statement, variables=[], extra_data={}, pagination_offset=None):
     super().__init__()
     self.client = GraphQLClient()
     self.statement = statement
     self.variables = variables
     self.extra_data = extra_data
     self.pagination_offset = pagination_offset
Ejemplo n.º 2
0
def test_ko():
    _add_response(500, {"error": "result"})
    client = GraphQLClient()
    with pytest.raises(click.ClickException) as e:
        client.get({"query": "request"})

    assert str(e.value) == '{"error": "result"}'
Ejemplo n.º 3
0
def test_ko_401():
    _add_response(401, {"error": "result"})
    client = GraphQLClient()
    with pytest.raises(click.ClickException) as e:
        client.get({"query": "request"})

    assert str(e.value) == "Unauthorized"
Ejemplo n.º 4
0
class GraphQLQuery(Query):
    def __init__(self, statement, variables=[], pagination_offset=None):
        super().__init__()
        self.client = GraphQLClient()
        self.statement = statement
        self.variables = variables
        self.pagination_offset = pagination_offset

    def _get_pagination_info(self):
        raise NotImplementedError()

    def execute(self):
        prepared_statement = prepare(self.statement, self.variables)
        if self.pagination_offset is None:
            response = self.client.get(prepared_statement)
            super()._handle_response(response)
            self._handle_response(response)
            return

        cursor = None
        has_next = True
        while has_next:
            paginated_statement = prepare_pagination(prepared_statement,
                                                     self.pagination_offset,
                                                     cursor)
            response = self.client.get(paginated_statement)
            super()._handle_response(response)
            self._handle_response(response)
            pagination_info = self._get_pagination_info(response)
            has_next = pagination_info["hasNextPage"]
            cursor = pagination_info["endCursor"]
Ejemplo n.º 5
0
class GraphQLQuery(Query):
    def __init__(self, statement, variables=[], extra_data={}, pagination_offset=None):
        super().__init__()
        self.client = GraphQLClient()
        self.statement = statement
        self.variables = variables
        self.extra_data = extra_data
        self.pagination_offset = pagination_offset

    def get_pagination_info(self):
        raise NotImplementedError()

    def get_count(self):
        raise NotImplementedError()

    @spin
    def execute(self, spinner):
        prepared_statement = prepare(self.statement, self.variables, self.extra_data)
        if self.pagination_offset is None:
            response = self.client.get(prepared_statement)
            super()._handle_response(response)
            self._handle_response(response)
            return

        cursor = None
        has_next = True
        while has_next:
            paginated_statement = prepare_pagination(prepared_statement, self.pagination_offset, cursor)
            response = self.client.get(paginated_statement)
            super()._handle_response(response)
            self._handle_response(response)
            count = self.get_count()
            if count > 0:
                spinner.text = "Loading... (yet {} entries found)".format(count)
            pagination_info = self.get_pagination_info(response)
            has_next = pagination_info["hasNextPage"]
            cursor = pagination_info["endCursor"]
Ejemplo n.º 6
0
def test_ok_200():
    _add_response(200, {"data": "result"})
    client = GraphQLClient()

    assert client.get({"query": "request"}) == {"data": "result"}