Resolvers

class magql.resolver_factory.Resolver

The super class for all builtin CRUD magql resolvers. Establishes the call order of the resolve functions. Resolve is broken down into 3 main sections, pre-resolve(), resolve(), and post-resolve(). re-resolve() allows modification of the arguments that will be passed to resolve(). resolve() is broken down into 4 sections, retrieve_value(), authorize(), validate(), and mutate(). resolve() returns a value that can be modified by post_resolve(), which can perform side effects such as commiting the session. The order of these functions is the suggested way of organizing the resolve order such that overriding and/or extending the functionality is easiest.

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Allows for modification of the returned value to GraphQl and performing of side effects :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info)

Retrieves (or creates) the value that the resolver will operate on and return. By default performs dot operation on the parent object using the field_name parameter of the info dict :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be operated on and returned to GraphQL

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

class magql.resolver_factory.CamelResolver

Identical to graphql’s default_field_resolver except the field_name is converted to snake case :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

class magql.resolver_factory.TableResolver(table)

A subclass of Resolver that adds a table so that it can be reused in QueryResolver and MutationResolver.

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Allows for modification of the returned value to GraphQl and performing of side effects :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info)

Retrieves (or creates) the value that the resolver will operate on and return. By default performs dot operation on the parent object using the field_name parameter of the info dict :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be operated on and returned to GraphQL

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

class magql.resolver_factory.MutationResolver(table)

Subclass of TableResolver. Initialized with a schema for validating the inputs. Its resolve method will call its validate method and return either the requested data of the changed object or an error dict filled with errors.

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

input_to_instance_values(input, mapper, session)

Helper method that converts the values in the input into values that can be passed into the creation of the instance. This returns scalars as themselves and passed id’s as an object or list of objects that can be set in the creation call. :param input: The user’s input dictionary containing the fields that are desired to be created. :param mapper: The mapper for the table that is being created :param session: The SQLAlchemy session :return: A dict of field names to values that will be added/changed on the newly created/modified object.

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Adds and commits the mutated value to the session :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info)

Retrieves (or creates) the value that the resolver will operate on and return. By default performs dot operation on the parent object using the field_name parameter of the info dict :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be operated on and returned to GraphQL

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

class magql.resolver_factory.QueryResolver(table)

A subclass of TableResolver, the super class for SingleResolver and ManyResolver

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

generate_query(info)

Generates a basic query based on the mapped class :param info: GraphQL info dict, used to hold the SQLA session :return: A SQLAlchemy query based on the mapped class, session.query(ModelClass)

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Allows for modification of the returned value to GraphQl and performing of side effects :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info)

Retrieves (or creates) the value that the resolver will operate on and return. By default performs dot operation on the parent object using the field_name parameter of the info dict :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be operated on and returned to GraphQL

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

class magql.resolver_factory.SingleResolver(table)

A subclass of QueryResolver. Takes an id and queries for the instance specified by id.

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

generate_query(info)

Generates a basic query based on the mapped class :param info: GraphQL info dict, used to hold the SQLA session :return: A SQLAlchemy query based on the mapped class, session.query(ModelClass)

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Allows for modification of the returned value to GraphQl and performing of side effects :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info, *args, **kwargs)

Retrieves the row in the table that matches the id in the args, if such a row exists :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be operated on and returned to GraphQL, in this case the row with id matching the requested id

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

class magql.resolver_factory.ManyResolver(table)

A subclass of QueryResolver. By default queries for all instances of the table that it is associated with. Can be filtered and sorted with keyword args.

authorize(instance, parent, info, *args, **kwargs)

Provides a space to perform authorization. Raise an AuthError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info

generate_query(info)

Generates a query based on the document ast :param info: GraphQL info dict. :return: A SQLAlchemy query with any needed subquery loads appended

generate_subqueryloads(field_node, load_path=None)

A helper function that allows the generation of the top level query to only have to perform one query with subqueryloads to eager load the data that will be accessed due to the structure of the query. Recursively builds a list of subquery loads that are applied to the base query. :param field_node: The document ast node that is used to determine what relationships are accessed by the query :param load_path: The load path that should be appended to in order to build the correct subquery :return: A list of all subqueries needed to eagerly load all data accessed as a result of the query

mutate(value, parent, info, *args, **kwargs)

Provides a space to mutate the resolved value. Necessarily will do nothing in queries. :param value: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the value that will be returned to GraphQL

post_resolve(resolved_value, parent, info, *args, **kwargs)

Allows for modification of the returned value to GraphQl and performing of side effects :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: The value to be returned to GraphQL

pre_resolve(parent, info, *args, **kwargs)

Allows for modification of the passed parameters :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info :return: the parameters that will be passed to resolve()

resolve(parent, info, *args, **kwargs)

Establishes the call order of the resolve sub_functions retrieve_value(), authorize(), validate(), and mutate(). When subclassing, define one of these subfunctions to overwrite or extend the functionality in a granular manner. To override functionality in a more major way define a new resolve function to perform desired behavior. :param parent: gql parent. is whatever was returned by the parent resolver :param info: gql info dictionary :return: The value to be returned to GraphQL

retrieve_value(parent, info, *args, **kwargs)

Returns all rows in a table. Uses subquery loads to improve querying by loading each relationship based on the query request :param parent: parent object required by GraphQL, always None because mutations are always top level. :param info: :param args: Not used but left in so that it can be used if a method is overriden :param kwargs: Holds the filters and sorts that can be used :return: A list of all rows in the table that match the filter, sorted by the given sort parameter.

validate(instance, parent, info, *args, **kwargs)

Provides a space to perform validation. Raise an ValidationError to stop execution and have the resolve method return an error message based on the string error in the error object :param instance: The value returned by retrieve_value() :param parent: gql parent. The value returned by the parent resolver. See GraphQL docs for more info :param info: GraphQL info dictionary, see GraphQL docs for more info