Sha256: fc1dac27f8bb734fda7541273e03310ad937fe9fa19ea5bf0caf45eff170a49f

Contents?: true

Size: 792 Bytes

Versions: 4

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module Osso
  module GraphQL
    module Mutations
      class RegenerateOauthCredentials < BaseMutation
        null false

        argument :id, ID, required: true

        field :oauth_client, Types::OauthClient, null: false
        field :errors, [String], null: false

        def resolve(id:)
          oauth_client = Osso::Models::OauthClient.find(id)
          oauth_client.generate_secrets

          return response_data(oauth_client: oauth_client) if oauth_client.save

          response_error(errors: oauth_client.errors.full_messages)
        end

        def ready?(*)
          return true if context[:scope] == :admin

          raise ::GraphQL::ExecutionError, 'Only admin users may mutate OauthClients'
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
osso-0.0.3.16 lib/osso/graphql/mutations/regenerate_oauth_credentials.rb
osso-0.0.3.15 lib/osso/graphql/mutations/regenerate_oauth_credentials.rb
osso-0.0.3.14 lib/osso/graphql/mutations/regenerate_oauth_credentials.rb
osso-0.0.3.13 lib/osso/graphql/mutations/regenerate_oauth_credentials.rb