Closed Ori-Shahar closed 11 months ago
Answer generated by a 🤖
I understand that you're encountering a TransportQueryError
when trying to use the GraphQL tool in LangChain. The error message suggests an authorization issue when fetching the schema from the GraphQL endpoint.
From your code, I see that you're passing an "Authorization" token in the custom_headers
parameter of the load_tools
function. However, the error message indicates that this token might not be valid or accepted by the GraphQL endpoint.
Firstly, I would recommend verifying the validity of your token and its permissions. If you're confident that the token is valid, it might be worth reaching out to the provider of the GraphQL API to understand if there are any additional requirements for authorization.
In LangChain, the GraphQLAPIWrapper
class is responsible for setting up the GraphQL client. It uses the gql
package to create a Client
instance with the provided graphql_endpoint
and custom_headers
. By default, the fetch_schema_from_transport
parameter is set to True
, which means the client will attempt to fetch the schema from the transport during initialization.
The error message suggests that you could try setting fetch_schema_from_transport=False
to bypass the schema fetching process. However, this parameter is currently hardcoded in the GraphQLAPIWrapper
class and cannot be changed externally. If you're comfortable with it, you might consider modifying the GraphQLAPIWrapper
class to allow this parameter to be set during instantiation.
Please note that while this could potentially resolve the authorization error, it might introduce other issues if your code relies on the schema being fetched from the transport.
This is just one potential solution based on the information provided. If you find this solution to be correct and believe it could benefit other users, you're encouraged to make a pull request with the necessary changes.
If this solution doesn't align with your experience, it might be worth checking if you're using the latest version of LangChain, as the issue might have been addressed in a more recent update.
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Solved:
GraphQLAPIWrapper overrides "client" when initializing, and by that it nullifies custom_headers.
To override it back its possible to explicitly do:
tools[0].graphql_wrapper.gql_client.transport = client.transport
And the TransportQueryError is solved.
Full code sample:
headers = custom_headers
transport = RequestsHTTPTransport(url=graphql_endpoint, headers=headers)
client = Client(transport=transport, fetch_schema_from_transport=True)
tools = load_tools(
["graphql"],
custom_headers=custom_headers,
graphql_endpoint=graphql_endpoint,
llm=llm
)
tools[0].graphql_wrapper.gql_client.transport = client.transport
This is fixed in this PR here: https://github.com/langchain-ai/langchain/pull/8187
Hi, I have the same issue. Graphql endpoint is public so I don't know why I should authenticate ?
Will the pull request solve this ?
Thanks :)
Hi, @Ori-Shahar! I'm Dosu, and I'm here to help the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.
Based on my understanding, you encountered a TransportQueryError
when using the GraphQL tool in the langchain library. The error message suggested an authorization issue when fetching the schema from the GraphQL endpoint. I provided a potential solution by suggesting to verify the validity of the token and its permissions, and to consider modifying the GraphQLAPIWrapper
class.
It seems that you were able to solve the TransportQueryError
by overriding the client
and you even shared a code sample to demonstrate the solution. Great job! Additionally, a pull request has been made to fix the issue. However, it's worth noting that another user, slamer59, has reported encountering the same issue.
Now, we would like to confirm if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your contribution and for helping us improve LangChain! If you have any further questions or concerns, please don't hesitate to reach out.
System Info
When running the following code:
Im getting the error: TransportQueryError: Error while fetching schema: {'errorType': 'UnauthorizedException', 'message': 'You are not authorized to make this call.'} If you don't need the schema, you can try with: "fetch_schema_from_transport=False"
It doesn't matter what value is provided under custom_headers, or if it is passed as a parameter at all. The error is always the same. Playground code from https://python.langchain.com/docs/modules/agents/tools/integrations/graphql worked as intended.
Any idea of what the problem is?
Who can help?
No response
Information
Related Components
Reproduction
Expected behavior
An allowed API call that doesn't cause authentication issues