def test_get_kwargs_in(_): selection = _.repository(name="foo", owner="blah")[_.id.page(eggs="good")] assert m.get_kwargs_in(selection, []) is None assert m.get_kwargs_in(selection, ["repository"]) == dict(name="foo", owner="blah") assert m.get_kwargs_in(selection, ["repository", "page"]) == dict(eggs="good") assert m.get_kwargs_in(selection, ["repository", "page", "does_not_exist"]) is None
def get_nested_next_page_request(exchange: RequestResponseExchange, child_resource: Resource, context: ChainMap) -> Optional[Request]: """for the req res exchange returns a Request for the next page of a nested resource (e.g. manifest deps or vuln alerts vulns) if any or None """ # path in the selection to add the parent after cursor params (can't get # from response since that cursor gives the next page of the parent # (alternatively could use a before param) parent_params = get_kwargs_in( exchange.request.graphql, exchange.request.resource.next_page_selection_path) assert parent_params is not None # NB: builds gql with 'null' as the after param but GH's API is OK with it context = ChainMap( dict(parent_after=parent_params.get("after", None)), context, get_owner_repo_kwargs(exchange.request.graphql), ) return Request( resource=child_resource, selection_updates=get_first_page_selection_updates( child_resource, context), )
def get_owner_repo_kwargs(last_graphql: quiz.Selection) -> Dict[str, str]: repo_kwargs = get_kwargs_in(last_graphql, ["repository"]) assert repo_kwargs is not None return extract_fields(repo_kwargs, ["owner", "name"])