8000 Trapping dependencies Exceptions into TransportConnectionFailed by leszekhanusz · Pull Request #558 · graphql-python/gql · GitHub
[go: up one dir, main page]

Skip to content

Trapping dependencies Exceptions into TransportConnectionFailed #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adding TransportConnectionFailed Exception to docs
  • Loading branch information
leszekhanusz committed May 28, 2025
commit 96b4f03a4033720d0ff15a23bb558118b9e5a97c
5 changes: 5 additions & 0 deletions docs/advanced/error_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Here are the possible Transport Errors:
If you don't need the schema, you can try to create the client with
:code:`fetch_schema_from_transport=False`

- :class:`TransportConnectionFailed <gql.transport.exceptions.TransportConnectionFailed>`:
This exception is generated when an unexpected Exception is received from the
transport dependency when trying to connect or to send the request.
For example in case of an SSL error, or if a websocket connection suddenly fails.

- :class:`TransportClosed <gql.transport.exceptions.TransportClosed>`:
This exception is generated when the client is trying to use the transport
while the transport was previously closed.
Expand Down
9 changes: 4 additions & 5 deletions gql/gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

def gql(request_string: str) -> GraphQLRequest:
"""Given a string containing a GraphQL request,
parse it into a Document and put it into a GraphQLRequest object
parse it into a Document and put it into a GraphQLRequest object.

:param request_string: the GraphQL request as a String
:return: a :class:`GraphQLRequest <gql.GraphQLRequest>`
which can be later executed or subscribed by a
:class:`Client <gql.client.Client>`, by an
:class:`async session <gql.client.AsyncClientSession>` or by a
:class:`sync session <gql.client.SyncClientSession>`

:class:`Client <gql.client.Client>`, by an
:class:`async session <gql.client.AsyncClientSession>` or by a
:class:`sync session <gql.client.SyncClientSession>`
:raises graphql.error.GraphQLError: if a syntax error is encountered.
"""
return GraphQLRequest(request_string)
11 changes: 4 additions & 7 deletions gql/graphql_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ def __init__(
variable_values: Optional[Dict[str, Any]] = None,
operation_name: Optional[str] = None,
):
"""
Initialize a GraphQL request.
"""Initialize a GraphQL request.

:param request: GraphQL request as DocumentNode object or as a string.
If string, it will be converted to DocumentNode.
:param variable_values: Dictionary of input parameters (Default: None).
:param operation_name: Name of the operation that shall be executed.
Only required in multi-operation documents (Default: None).

:return: a :class:`GraphQLRequest <gql.GraphQLRequest>`
which can be later executed or subscribed by a
:class:`Client <gql.client.Client>`, by an
:class:`async session <gql.client.AsyncClientSession>` or by a
:class:`sync session <gql.client.SyncClientSession>`
:class:`Client <gql.client.Client>`, by an
:class:`async session <gql.client.AsyncClientSession>` or by a
:class:`sync session <gql.client.SyncClientSession>`
:raises graphql.error.GraphQLError: if a syntax error is encountered.

"""
if isinstance(request, str):
source = Source(request, "GraphQL request")
Expand Down
5 changes: 3 additions & 2 deletions gql/transport/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ class TransportClosed(TransportError):


class TransportConnectionFailed(TransportError):
"""Transport adapter connection closed.
"""Transport connection failed.

This exception is by the connection adapter code when a connection closed.
This exception is by the connection adapter code when a connection closed
or if an unexpected Exception was received when trying to send a request.
"""


Expand Down
Loading
0