| 75 | pass |
| 76 | |
| 77 | def graphql(self, query: str, **kwargs: Any) -> Any: |
| 78 | headers = {} |
| 79 | if self.oauth_token: |
| 80 | headers["Authorization"] = "bearer {}".format(self.oauth_token) |
| 81 | |
| 82 | logging.debug( |
| 83 | "# POST {}".format(self.graphql_endpoint.format(github_url=self.github_url)) |
| 84 | ) |
| 85 | logging.debug("Request GraphQL query:\n{}".format(query)) |
| 86 | logging.debug( |
| 87 | "Request GraphQL variables:\n{}".format(json.dumps(kwargs, indent=1)) |
| 88 | ) |
| 89 | |
| 90 | resp = requests.post( |
| 91 | self.graphql_endpoint.format(github_url=self.github_url), |
| 92 | json={"query": query, "variables": kwargs}, |
| 93 | headers=headers, |
| 94 | proxies=self._proxies(), |
| 95 | verify=self.verify, |
| 96 | cert=self.cert, |
| 97 | ) |
| 98 | |
| 99 | logging.debug("Response status: {}".format(resp.status_code)) |
| 100 | |
| 101 | try: |
| 102 | r = resp.json() |
| 103 | except ValueError: |
| 104 | logging.debug("Response body:\n{}".format(resp.text)) |
| 105 | raise |
| 106 | else: |
| 107 | pretty_json = json.dumps(r, indent=1) |
| 108 | logging.debug("Response JSON:\n{}".format(pretty_json)) |
| 109 | |
| 110 | # Actually, this code is dead on the GitHub GraphQL API, because |
| 111 | # they seem to always return 200, even in error case (as of |
| 112 | # 11/5/2018) |
| 113 | try: |
| 114 | resp.raise_for_status() |
| 115 | except requests.HTTPError: |
| 116 | raise RuntimeError(pretty_json) |
| 117 | |
| 118 | if "errors" in r: |
| 119 | raise RuntimeError(pretty_json) |
| 120 | |
| 121 | return r |
| 122 | |
| 123 | def _proxies(self) -> Dict[str, str]: |
| 124 | if self.proxy: |