API Gateway

In order to reduce coupling between the individual services that make up your application, the api provided by an APIGateway service builds its graphql schema by waiting for services annouce their contributions when starting up and piecing together the complete summary of data availible from the backend services.

class nautilus.APIGateway(*args, **kwds)[source]

This provides a single endpoint that other services and clients can use to query the cloud without worrying about the distributed nature of the system.

Example

# external imports
import nautilus

# local imports
from .schema import schema

class MyAPIGateway(nautilus.APIGateway):
    schema = schema
action_handler

alias of APIActionHandler

api_request_handler_class

alias of APIQueryHandler

auth_criteria

This attribute provides the mapping of services to their auth requirement

Returns:the mapping from services to their auth requirements.
Return type:(dict)
get_models()[source]

Returns the models managed by this service.

Returns:the models managed by the service
Return type:(list)
init_db()[source]

This function configures the database used for models to make the configuration parameters.

login_user(password, **kwds)[source]

This function handles the registration of the given user credentials in the database

mutation_resolver(mutation_name, args, fields)[source]

the default behavior for mutations is to look up the event, publish the correct event type with the args as the body, and return the fields contained in the result

object_resolver(object_name, fields, obey_auth=False, current_user=None, **filters)[source]

This function resolves a given object in the remote backend services

register_user(password, **kwds)[source]

This function is used to provide a sessionToken for later requests.

Parameters:uid (str) – The
user_session(user)[source]

This method handles what information the api gateway stores about a particular user in their session.

Filtering the API

The API for ModelService s (and other services based on them like ConnectionService) have a few different filter arguments depending on the type of the attribute. The following filters show on both the API gateway as well as the inidividual service apis:

Filter Value type Attribute type Returns
<attr> same as attribute literal all records with the matching attribute value
<attr>_in list of attribute type literal all records with a value in the specified list
first integer any return the first N records
last integer any return the last N records
offset integer any start the count filters at a given offset

Designating a GraphQL Equivalent of a Nautilus Field

If you create (or find) a custom field that is compatible with peewee, the ORM used by nautilus internally, you might find the need to provide a custom handler in order for the schema generator to be able to convert it to the correct GraphQL type.

nautilus.contrib.graphene_peewee.converter()

This module defines various patches for peewee to easily interact with graphene.

This function follows the [singledispatch] pattern. Registering a new type looks something like:

from awesomepackage import AwesomeField
from nautilus.contrib.graphene_peewee import converter

@converter.register(AwesomeField)
def convert_field_to_string(field):
    return String(description = field.doc)