Skip to content

The *ServiceProxy Objects

The *ServiceProxy objects (QueryServiceProxy, ...) are simple objects that check if an operation exists for the attribute or item requested.

If the operation exists then it will return a *OperationProxy object (callable) that is responsible for creating the request and sending it to the backend.

from qlient.core import Client

client = Client(...)

# "query" is a QueryServiceProxy object.
# It will check if there is an operation
# with the name "X" defined in the query type
# and if that is the case it will return an QueryOperationProxy.
client.query.X()

# The operation cal also be called via an __getitem__ call.
# This is useful if the operation name is not a valid
# python attribute name.
client.query["X-Y"]()

Create the raw request

from qlient.core import Client, GraphQLRequest

client = Client(...)

request: GraphQLRequest = client.query.X.create_request(["foo", "bar"], foo="test")

print(request.query)  # "query X($foo: String) { X(foo: $foo) { foo bar } }"
print(request.variables)  # {"foo": "test"}