Skip to content

Commit

Permalink
community[patch]: Allow override of 'fetch_schema_from_transport' in …
Browse files Browse the repository at this point in the history
…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 <zt10191991@hotmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
  • Loading branch information
3 people committed Feb 21, 2024
1 parent 3189109 commit 29ee049
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions libs/community/langchain_community/utilities/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions libs/community/tests/unit_tests/utilities/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion libs/langchain/langchain/agents/load_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ def _get_reddit_search(**kwargs: Any) -> BaseTool:
),
"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,
Expand Down

0 comments on commit 29ee049

Please sign in to comment.