This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Description
The mutation:
module MyApp::GraphQL::Types::Mutations
module Groups
extend ActiveSupport::Concern
included do
field :create_sub_group, MyApp::GraphQL::Types::Objects::Group, null: false, authorize!: true, description: "Add a sub group to a group" do
argument :parent_group_id, String, "Parent group id", required: true
argument :name, String, "Group name", required: true
argument :description, String, "Group description (optional)", required: false
end
end
def create_sub_group(parent_group_id:, name:, description:)
group = MyApp::Models::Group.create(parent_group_id: parent_group_id,
name: name, description: description, owner: context[:current_user])
if group.persisted?
group
else
GraphQL::ExecutionError.new(group.errors.full_messages.join(". "), extensions: { code: 'unprocessable_entity' })
end
end
end
end
The policy:
module MyApp
module Policies
class MutationTypePolicy < MyApp::Policies::ApplicationPolicy
def create_sub_group?
!user.nil? && record.arguments[:parent_group_id] == 'xxx'
end
end
end
end
The part that does not work is obviously: record.arguments[:parent_group_id] == 'xxx' because I totally made it up. But it's to illustrate what I am trying to do ?
I can't seem to figure out a way to achieve that.
This is all I got when I am in that method:
[7] pry(#<MyApp::Policies::MutationTypePolicy>)> self
=> #< MyApp::Policies::MutationTypePolicy:0x00007fc2f2cce0e0
@record=#< MyApp::GraphQL::Types::MutationType:0x00007fc2f2cdbab0 @context=#<Query::Context ...>, @object=nil>,
@user=#< MyApp::Models::User _id: "acb09ad2-1cd6-4850-9fb1-4f14153e8006", created_at: Tue, 14 Aug 2018 22:15:20 UTC +00:00, email: "[email protected]", updated_at: Tue, 14 Aug 2018 22:37:16 UTC +00:00>>