Resolver
The most common way to assign a specific resolver to a field is to decorate your resolver callable with the @Resolver
decorator. Your resolver MUST BE compliant with the resolver signature and be async
.
from tartiflette import Resolver
@Resolver("Query.hello")
async def my_hello_resolver(parent, args, context, info):
return "Chuck"
Decorator signature
name
(str): fully qualified field name to resolveschema_name
(str = "default"): name of the schema to which link the resolvertype_resolver
(Optional[Callable] = None): the callable to use to resolve the type of an abstract typearguments_coercer
(Optional[Callable] = None): callable to use to coerce field argumentsconcurrently
(Optional[bool] = None): determine whether or not the output list of the decorated field should be coerced concurrently
The arguments_coercer
parameter is here to provide an easy way to override the default callable used internaly by Tartiflette to coerce the arguments of the field. It has the same behaviour as the custom_default_arguments_coercer
parameter at engine initialisation but impact only the field.
Resolver 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