Class: Extension::Tasks::UpdateDraft

Inherits:
ShopifyCLI::Task show all
Includes:
UserErrors
Defined in:
lib/project_types/extension/tasks/update_draft.rb

Constant Summary collapse

GRAPHQL_FILE =
"extension_update_draft"
RESPONSE_FIELD =
%w(data extensionUpdateDraft)
VERSION_FIELD =
"extensionVersion"

Constants included from UserErrors

Extension::Tasks::UserErrors::MESSAGE_FIELD, Extension::Tasks::UserErrors::USER_ERRORS_FIELD, Extension::Tasks::UserErrors::USER_ERRORS_PARSE_ERROR

Instance Method Summary collapse

Methods included from UserErrors

#abort_if_user_errors

Instance Method Details

#call(context:, api_key:, registration_id:, config:, extension_context:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/project_types/extension/tasks/update_draft.rb', line 14

def call(context:, api_key:, registration_id:, config:, extension_context:)
  input = {
    api_key: api_key,
    registration_id: registration_id,
    config: JSON.generate(config),
    extension_context: extension_context,
  }
  response = ShopifyCLI::PartnersAPI.query(context, GRAPHQL_FILE, **input).dig(*RESPONSE_FIELD)
  context.abort(context.message("tasks.errors.parse_error")) if response.nil?

  abort_if_user_errors(context, response)
  Converters::VersionConverter.from_hash(context, response.dig(VERSION_FIELD))
end