Resolver
The most common way to assign a specific resolver to a field is to decorate your resolver callable with the @Resolver
decorator. Your function MUST BE compliant with the function signature and be async
.
from tartiflette import Resolver
@Resolver("Query.hello")
async def my_hello_resolver(parent, args, context, info):
return "Chuck"
Function signature
Every resolver in Tartiflette accepts four positional arguments:
(This signature is highly inspired by the GraphQL.js implementation)
async def my_hello_resolver(
parent: Optional[Any],
args: Dict[str, Any],
ctx: Optional[Any],
info: "ResolveInfo",
) -> Any:
pass
parent
(Optional[Any]): resolved value returned by the parent resolver field, if the parent is a root type (Query/Mutation/Subscription) the value passed will be theinitial_value
of the executionargs
(Dict[str, Any]): a dictionary containing the arguments passed for the field. (in the query). e.g. if the field was called withhello(name: "Chuck")
, theargs
dictionary will be equals to{"name": "Chuck"}
ctx
(Optional[Any]): will be the value of thecontext
argument provided when calling theexecute
orsubscribe
'sEngine
methodinfo
("ResolveInfo"): internal Tartiflette object containing information related to the execution and the resolved field. It CAN BE used for advanced use-cases (more detail here)
info
argument
Resolver The info
argument contains information related to the execution and the resolved field which can be useful for middlewares and advanced use-cases.
Here are the available properties:
field_name
(str): name of the resolved fieldfield_nodes
(List["FieldNodes"]): AST nodes related to the resolved fieldreturn_type
("GraphQLOutputType"): GraphQLOutputType instance of the resolved fieldparent_type
("GraphQLObjectType"): GraphQLObjectType of the field's parentpath
("Path"): the path traveled until this fieldschema
("GraphQLSchema"): the GraphQLSchema instance linked to resolved fieldfragments
(Dict[str, "FragmentDefinitionNode"]): a dictionary of fragment definition AST nodes contained in the requestroot_value
(Optional[Any]): the initial value corresponding to provided value atexecute
orsubscribe
method calloperation
("OperationDefinitionNode"): the AST operation definition node to executevariable_values
(Optional[Dict[str, Any]]): the variables provided in the GraphQL requestis_introspection
(bool): determines whether or not the resolved field is in a context of an introspection query