Implementing ActiveQL
ResolverHooks

Resolver Hooks

An easy way to extend the implementation of ActiveQL resolvers are entity hooks.

The recommended way is to use the entity's onInit method to add your own implementation to the entity's hooks.

export const domainConfiguration: DomainConfiguration = {
  entity: {
    Car: {
      onInit: entity => {        
        entity.hooks.beforeSave.push( (params:ResolverParams) => {
          if( ! rhc.resolverParams.args.color ) rhc.resolverParams.args.color = 'unknown';
        })
      }
    }
  }
}

Hook Context

Inside a hook you have access to the ResolverParams which holds the data from the GraphQL layer, the principal and the runtime which you can use to perform any task or influencing the default implementation.

Hook Control Flow

The beforeXXX hooks can interrupt the normal execution flow by returning an object. This would be handled as the result that will be sent to the client. In other words - if all beforeXXX hooks returns undefined or void the regular implementation (incl. all other hooks) will be executed. If any hook returns an object - neither the regular implementation nor any other hooks will be performed and the object is returned as operations the result to the client.

In the the afterXXX hooks you also get the resolved value that is about to being sent to the client. You can manipulate this according to your requirements before it is sent to the client.