docs/components/controller.md in graphql_rails-0.3.3 vs docs/components/controller.md in graphql_rails-0.4.0

- old
+ new

@@ -78,11 +78,11 @@ By default return type is determined by controller name. When you want to return some custom object, you can specify that with `returns` method: ```ruby class UsersController < GraphqlRails::Controller - action(:last_order).permit(:id).returns(Order) + action(:last_order).permit(:id).returns('Order!') # Order is your model class name def last_order user = User.find(params[:id]).orders.last end end @@ -116,9 +116,51 @@ private def require_auth_token # will run before `UsersController#create` action raise 'Not authenticated' unless User.where(token: params[:token]).exist? + end +end +``` + +## *after_action* + +You can add `after_action` to run some filters after calling your controller action. Here is an example: + +```ruby +class UsersController < GraphqlRails::Controller + after_action :clear_cache + + def create + User.create(params) + end + + private + + def clear_cache # will run after `UsersController#create` action + logger.log('Create action is completed') + end +end +``` + +## *around_action* + +You can add `around_action` to run some filters before and after calling your controller action. Here is an example: + +```ruby +class UsersController < GraphqlRails::Controller + around_action :use_custom_locale + + def create + User.create(params) + end + + private + + def with_custom_locale + I18n.with_locale('it') do + yield # yield is mandatory + end end end ``` ### *only* and *except* option