Class: Ecoportal::API::GraphQL::Mutation::Template::Create

Inherits:
Logic::Mutation
  • Object
show all
Defined in:
lib/ecoportal/api/graphql/mutation/template/create.rb

Overview

createPageTemplate(input: CreatePageTemplateInput!) — creates a template page from a WorkflowCommand batch.

★ registerId IS NOT COSMETIC — it is what makes the create AUTHORIZABLE.

The backend resolves a page's registers BY TAG (NewEp::Pages::AssociatedRegisters: org registers whose filter_tags are a subset of the page's combined_tags), and RegisterTemplatePermissionChecker returns false outright when that set is EMPTY. A template created without registerId carries no base_tags, so it is associated with ZERO registers, so the check fails regardless of what the account is granted — surfacing as the misleading You are not authorized to perform: edit_template_basic_settings. Pages::Templates::CreateForm#bind_register! is what closes that hole: given register_id it sets page.base_tags = register.filter_tags BEFORE the commands run.

SHAPE (verified against the LIVE eu.live SDL, 2026-09-04): registerId: ID is an INPUT FIELD of CreatePageTemplateInput, not a sibling argument of the mutation — the backend mutation declares argument :register_id, ID, required: false next to argument :commands, but Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation folds every argument into the generated input object. So it travels inside input:, exactly like commands.

Constant Summary collapse

SCHEMA_VERSION =
'20260904'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Logic::Mutation

#response_class

Class Method Details

.build_input(commands:, register_id: nil) ⇒ Object

Extracted so the omit-nil rule is testable without a client or a network stub.



43
44
45
46
47
# File 'lib/ecoportal/api/graphql/mutation/template/create.rb', line 43

def self.build_input(commands:, register_id: nil)
  {commands: commands}.tap do |input|
    input[:registerId] = register_id unless register_id.nil?
  end
end

Instance Method Details

#query(commands:, register_id: nil, **kargs, &block) ⇒ Object

Parameters:

  • commands (Array<Hash>) —

    the WorkflowCommand batch.

  • register_id (String, nil) (defaults to: nil) —

    the register to bind the new template to. Omitted when nil — never sent as an explicit null, so existing call sites keep producing the byte-identical input they produced before this key existed.



38
39
40
# File 'lib/ecoportal/api/graphql/mutation/template/create.rb', line 38

def query(commands:, register_id: nil, **kargs, &block)
  super(input: self.class.build_input(commands: commands, register_id: register_id), **kargs, &block)
end