From 29ee0496b6aa0862db3ccdb7c832de2686fef553 Mon Sep 17 00:00:00 2001 From: Zachary Toliver Date: Wed, 21 Feb 2024 17:32:43 -0600 Subject: [PATCH] community[patch]: Allow override of 'fetch_schema_from_transport' in the GraphQL tool (#17649) - **Description:** In order to override the bool value of "fetch_schema_from_transport" in the GraphQLAPIWrapper, a "fetch_schema_from_transport" value needed to be added to the "_EXTRA_OPTIONAL_TOOLS" dictionary in load_tools in the "graphql" key. The parameter "fetch_schema_from_transport" must also be passed in to the GraphQLAPIWrapper to allow reading of the value when creating the client. Passing as an optional parameter is probably best to avoid breaking changes. This change is necessary to support GraphQL instances that do not support fetching schema, such as TigerGraph. More info here: [TigerGraph GraphQL Schema Docs](https://docs.tigergraph.com/graphql/current/schema) - **Threads handle:** @zacharytoliver --------- Co-authored-by: Zachary Toliver Co-authored-by: Bagatur --- libs/community/langchain_community/utilities/graphql.py | 1 + libs/community/tests/unit_tests/utilities/test_graphql.py | 1 + libs/langchain/langchain/agents/load_tools.py | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/utilities/graphql.py b/libs/community/langchain_community/utilities/graphql.py index a576419e5b..0478aef78e 100644 --- a/libs/community/langchain_community/utilities/graphql.py +++ b/libs/community/langchain_community/utilities/graphql.py @@ -12,6 +12,7 @@ class GraphQLAPIWrapper(BaseModel): """ custom_headers: Optional[Dict[str, str]] = None + fetch_schema_from_transport: Optional[bool] = None graphql_endpoint: str gql_client: Any #: :meta private: gql_function: Callable[[str], Any] #: :meta private: diff --git a/libs/community/tests/unit_tests/utilities/test_graphql.py b/libs/community/tests/unit_tests/utilities/test_graphql.py index 2ef9be654b..82c75e21c0 100644 --- a/libs/community/tests/unit_tests/utilities/test_graphql.py +++ b/libs/community/tests/unit_tests/utilities/test_graphql.py @@ -85,6 +85,7 @@ def test_run() -> None: graphql_wrapper = GraphQLAPIWrapper( graphql_endpoint=TEST_ENDPOINT, custom_headers={"Authorization": "Bearer testtoken"}, + fetch_schema_from_transport=True, ) result = graphql_wrapper.run(query) diff --git a/libs/langchain/langchain/agents/load_tools.py b/libs/langchain/langchain/agents/load_tools.py index 24adaf867d..ab49c39a4a 100644 --- a/libs/langchain/langchain/agents/load_tools.py +++ b/libs/langchain/langchain/agents/load_tools.py @@ -453,7 +453,10 @@ _EXTRA_OPTIONAL_TOOLS: Dict[str, Tuple[Callable[[KwArg(Any)], BaseTool], List[st ), "stackexchange": (_get_stackexchange, []), "sceneXplain": (_get_scenexplain, []), - "graphql": (_get_graphql_tool, ["graphql_endpoint", "custom_headers"]), + "graphql": ( + _get_graphql_tool, + ["graphql_endpoint", "custom_headers", "fetch_schema_from_transport"], + ), "openweathermap-api": (_get_openweathermap, ["openweathermap_api_key"]), "dataforseo-api-search": ( _get_dataforseo_api_search,