gql.transport.httpx

class gql.transport.httpx.HTTPXTransport(url: ~typing.Union[str, ~httpx.URL], json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, **kwargs)

Bases: Transport, _HTTPXTransport

Sync Transport used to execute GraphQL queries on remote servers.

The transport uses the httpx library to send HTTP POST requests.

client: Optional[Client] = None
connect()

Establish a session with the transport.

execute(document: DocumentNode, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, extra_args: Optional[Dict[str, Any]] = None, upload_files: bool = False) ExecutionResult

Execute GraphQL query.

Execute the provided document AST against the configured remote server. This uses the httpx 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).

  • extra_args – additional arguments to send to the httpx 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

__init__(url: ~typing.Union[str, ~httpx.URL], json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, **kwargs)

Initialize the transport with the given httpx parameters.

Parameters
  • url – The GraphQL server URL. Example: ‘https://server.com:PORT/path’.

  • json_serialize – Json serializer callable. By default json.dumps() function.

  • json_deserialize – Json deserializer callable. By default json.loads() function.

  • kwargs – Extra args passed to the httpx client.

execute_batch(reqs: List[GraphQLRequest], *args, **kwargs) List[ExecutionResult]

Execute multiple GraphQL requests in a batch.

Execute the provided requests for either a remote or local GraphQL Schema.

Parameters

reqs – GraphQL requests as a list of GraphQLRequest objects.

Returns

a list of ExecutionResult objects

file_classes: Tuple[Type[Any], ...] = (<class 'io.IOBase'>,)
response_headers: Optional[Headers] = None
class gql.transport.httpx.HTTPXAsyncTransport(url: ~typing.Union[str, ~httpx.URL], json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, **kwargs)

Bases: AsyncTransport, _HTTPXTransport

Async Transport used to execute GraphQL queries on remote servers.

The transport uses the httpx library with anyio.

client: Optional[AsyncClient] = None
async connect()

Coroutine used to create a connection to the specified address

async execute(document: DocumentNode, variable_values: Optional[Dict[str, Any]] = None, operation_name: Optional[str] = None, extra_args: Optional[Dict[str, Any]] = None, upload_files: bool = False) ExecutionResult

Execute GraphQL query.

Execute the provided document AST against the configured remote server. This uses the httpx library to perform a HTTP POST request asynchronously 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).

  • extra_args – additional arguments to send to the httpx 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.

async close()

Closing the transport by closing the inner session

__init__(url: ~typing.Union[str, ~httpx.URL], json_serialize: ~typing.Callable = <function dumps>, json_deserialize: ~typing.Callable = <function loads>, **kwargs)

Initialize the transport with the given httpx parameters.

Parameters
  • url – The GraphQL server URL. Example: ‘https://server.com:PORT/path’.

  • json_serialize – Json serializer callable. By default json.dumps() function.

  • json_deserialize – Json deserializer callable. By default json.loads() function.

  • kwargs – Extra args passed to the httpx client.

file_classes: Tuple[Type[Any], ...] = (<class 'io.IOBase'>,)
response_headers: Optional[Headers] = None