Sha256: d1b65fb49e1d4b52fdf9f67f32baf1b06d3e3556769da131e6979489a11513ec

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

module Osso
  module GraphQL
    module Mutations
      class BaseMutation < ::GraphQL::Schema::RelayClassicMutation
        object_class Types::BaseObject
        input_object_class Types::BaseInputObject

        def response_data(data)
          data.merge(errors: [])
        end

        def response_error(error)
          error.merge(data: nil)
        end

        def ready?(enterprise_account_id: nil, domain: nil, **args)
          return true if context[:scope] == :admin

          domain ||= account_domain(enterprise_account_id)
          return true if domain == context[:scope]

          raise ::GraphQL::ExecutionError, "This user lacks the scope to mutate records belonging to #{args[:domain]}"
        end

        def account_domain(id)
          return false unless id

          Osso::Models::EnterpriseAccount.find(id)&.domain
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
osso-0.0.3.6 lib/osso/graphql/mutations/base_mutation.rb