Execution
Aside from building the Engine
, the execute
method is responsible for executing the GraphQL query coming from the client.
Its parameters are:
query
(Union[str, bytes]): the GraphQL request/query as UTF8-encoded stringoperation_name
(Optional[str]): the operation name to executecontext
(Optional[Any]): value containing anything you could need and which will be available during all the execution processvariables
(Optional[Dict[str, Any]]): the variables provided in the GraphQL requestinitial_value
(Optional[Any]): an initial value which will be forwarded to the resolver of root type (Query/Mutation/Subscription) fields
from tartiflette import create_engine
engine = await create_engine(
"myDsl.graphql"
)
result = await engine.execute(
query="query MyVideo($id: String!) { video(id: $id) { id title } }",
operation_name="MyVideo",
context={
"mysql_client": MySQLClient(),
"auth_info": AuthInfo(),
},
variables={
"id": "1234",
},
initial_value={},
)
# `result` will contains something like
# {
# "data": {
# "video": {
# "id": "1234",
# "title": "My fabulous title"
# }
# }
# }