gql.transport.requests¶
-
class
gql.transport.requests.
RequestsHTTPTransport
(url: str, headers: Optional[Dict[str, Any]] = None, cookies: Optional[Union[Dict[str, Any], requests.cookies.RequestsCookieJar]] = None, auth: Optional[requests.auth.AuthBase] = None, use_json: bool = True, timeout: Optional[int] = None, verify: Union[bool, str] = True, retries: int = 0, method: str = 'POST', **kwargs: Any)¶ Bases:
gql.transport.transport.Transport
Sync Transport used to execute GraphQL queries on remote servers.
The transport uses the requests library to send HTTP POST requests.
-
file_classes
: Tuple[Type[Any], …] = (<class 'io.IOBase'>,)¶
-
__init__
(url: str, headers: Optional[Dict[str, Any]] = None, cookies: Optional[Union[Dict[str, Any], requests.cookies.RequestsCookieJar]] = None, auth: Optional[requests.auth.AuthBase] = None, use_json: bool = True, timeout: Optional[int] = None, verify: Union[bool, str] = True, retries: int = 0, method: str = 'POST', **kwargs: Any)¶ Initialize the transport with the given request parameters.
- Parameters
url – The GraphQL server URL.
headers – Dictionary of HTTP Headers to send with the
Request
(Default: None).cookies – Dict or CookieJar object to send with the
Request
(Default: None).auth – Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth (Default: None).
use_json – Send request body as JSON instead of form-urlencoded (Default: True).
timeout – Specifies a default timeout for requests (Default: None).
verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. (Default: True).
retries – Pre-setup of the requests’ Session for performing retries
method – HTTP method used for requests. (Default: POST).
kwargs – Optional arguments that
request
takes. These can be seen at the requests source code or the official docs
-
connect
()¶ Establish a session with the transport.
-
execute
(document: graphql.language.ast.DocumentNode, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, timeout: Optional[int] = None, extra_args: Optional[Dict[str, Any]] = None, upload_files: bool = False) → graphql.execution.execute.ExecutionResult¶ Execute GraphQL query.
Execute the provided document AST against the configured remote server. This uses the requests library to perform a HTTP POST request to the remote server.
- Parameters
document – GraphQL query as AST Node object.
variable_values – Dictionary of input parameters (Default: None).
operation_name – Name of the operation that shall be executed. Only required in multi-operation documents (Default: None).
timeout – Specifies a default timeout for requests (Default: None).
extra_args – additional arguments to send to the requests post method
upload_files – Set to True if you want to put files in the variable values
- Returns
The result of execution. data is the result of executing the query, errors is null if no errors occurred, and is a non-empty array if an error occurred.
-
close
()¶ Closing the transport by closing the inner session
-