MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / graphql_node

Method graphql_node

github/Requester.py:742–787  ·  view source on GitHub ↗

Fetches a GraphQL node by id in the give schema. This sends the following GraphQL request:: query Q($id. ID!) { node(id: $id) { __typename ... on { }

(self, node_id: str, output_schema: str, node_type: str)

Source from the content-addressed store, hash-verified

740 return self.data_as_class(headers, data, ["data"] + data_path, klass)
741
742 def graphql_node(self, node_id: str, output_schema: str, node_type: str) -> tuple[dict[str, Any], dict[str, Any]]:
743 """
744 Fetches a GraphQL node by id in the give schema.
745
746 This sends the following GraphQL request::
747
748 query Q($id. ID!) {
749 node(id: $id) {
750 __typename
751 ... on <node_type> {
752 <output_schema>
753 }
754 }
755 }
756
757 :param node_id: GraphQL node id
758 :param output_schema: The schema of the retrieved properties of the node, without enclosing curly brackets
759 :param node_type: The GraphQL node type
760 :return: ``(headers: dict, JSON Response: dict)``
761 :raises: :class:`GithubException` for error status codes
762
763 """
764 if not output_schema.startswith("\n"):
765 output_schema = f" {output_schema} "
766 query = (
767 """
768 query Q($id: ID!) {
769 node(id: $id) {
770 __typename
771 ... on """
772 + f"{node_type} {{{output_schema}}}"
773 + """
774 }
775 }
776 """
777 )
778
779 headers, data = self.graphql_query(query, {"id": node_id})
780 actual_node_type = data.get("data", {}).get("node", {}).get("__typename", node_type)
781 if actual_node_type != node_type:
782 raise github.GithubException(
783 400,
784 data,
785 message=f"Retrieved {node_type} object is of different type: {actual_node_type}",
786 )
787 return headers, data
788
789 def graphql_node_class(
790 self, node_id: str, output_schema: str, klass: type[T_gh], node_type: str | None = None

Callers 2

graphql_node_classMethod · 0.95
testNodeMethod · 0.80

Calls 2

graphql_queryMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected