Class: Ecoportal::API::GraphQL::Query::TemplateChangeLog

Inherits:
Logic::QueryConnection show all
Defined in:
lib/ecoportal/api/graphql/query/template_change_log.rb

Overview

TEMPLATE CHANGE LOG — "for template X, who changed what, and when", newest first, paginated.

Read path (verified in the Rails backend on 2026-08-19):

currentOrganization.page(id:) → template → commands

There is NO top-level query for the narrow Template type. template is declared on app/graphql/types/pages/interfaces/base_page_interface.rb:27, so it is reachable on any page — and a template IS a page in this platform, so pass the TEMPLATE's page id.

currentOrganization.page(id:) returns a PageUnion, so template has to be selected through a type condition on BasePageInterface — selecting directly on a union is invalid GraphQL under any schema (this is the class of bug the validate-queries CI gate hard-fails on). The type condition does not change the response shape, so #path still digs currentOrganization → page → template → commands.

★ Access caveats and the forces watermark blind spot are documented on Base::Template::ChangeLogEntry. In short: a nil commands connection means the caller lacks Pages::TemplatePolicy#update_information?, NOT that nothing changed; and only TEMPLATE_BUILDER-sourced commands appear here (workflow-builder ones live on Query::PagesWorkflowCommands).

Usage:

q = Query::TemplateChangeLog.new(client)
conn = q.query(id: template_page_id, first: 50)
conn.nodes.each { |e| puts "#{e.createdAt.dateTime} #{e.owner&.name} #{e.commandAction}" }

# auto-paginating enumerator (Logic::QueryConnection#each)
q.each(id: template_page_id, first: 100) { |entry| ... }

Also reachable as api.template.change_log(id:, first:) — see Builder::Template.

★ For WHAT CHANGED (field/from/to, change messages) pass detail: true to the builder, or &Query::TemplateChangeLog.detail_block here. The default selection deliberately omits it so the common "who and when" read stays cheap.

Constant Summary collapse

SCHEMA_VERSION =
'20260819'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Logic::QueryConnection

#each, #response_class

Class Method Details

.detail_block ⇒ Object

Connection block that selects FIELD-LEVEL DETAIL as well -- what changed, not just who/when/which-resource. Opt-in, because it adds three inline fragments and their sub-selections to every node.

q = Query::TemplateChangeLog.new(client)
conn = q.query(id: template_page_id, first: 50, &described_class.detail_block)
conn.nodes.each do |e|
case e.detail_kind
when :changes         then e.changes.each { |c| puts "#{c['field']}: #{c['from']} -> #{c['to']}" }
when :change_messages then puts e.changeMessages.join('; ')
when :es_changes      then puts "filter changed: #{e.changes.map { |c| c['field'] }.join(', ')}"
end
end

Or simply api.template.change_log(id:, first:, detail: true).



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ecoportal/api/graphql/query/template_change_log.rb', line 70

def self.detail_block
  proc {
    totalCount
    pageInfo {
      endCursor
      hasNextPage
    }
    nodes {
      spread :TemplateChangeLogEntryDetail
    }
  }
end

Instance Method Details

#path ⇒ Object

Absolute — the connection is nested three levels deep, so it is not expressible as base_path + field_name.



51
52
53
# File 'lib/ecoportal/api/graphql/query/template_change_log.rb', line 51

def path
  %w[currentOrganization page template commands]
end