Class: HasHelpers::Resolvers::Cards::HoverCardData

Inherits:
GraphQL::Schema::Resolver
  • Object
show all
Defined in:
app/graphql/has_helpers/resolvers/cards/hover_card_data.rb

Instance Method Summary collapse

Instance Method Details

#resolve(resource_name:, record_id:, identifier:, role_id: nil) ⇒ Object

Hover-only cards are not persisted. We assemble an in-memory CardDefinition (and its CardField rows) from the DSL registry and hand it off to CardDataCommand via the dedicated entry point.

Raises:

  • (GraphQL::ExecutionError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/graphql/has_helpers/resolvers/cards/hover_card_data.rb', line 17

def resolve(resource_name:, record_id:, identifier:, role_id: nil)
  _ = role_id
  app = context[:current_application]
  raise GraphQL::ExecutionError, "current_application missing from GraphQL context" if app.nil?

  resource = ::HasHelpers::Resource.find_by!(
    name: resource_name.to_s,
    application_id: app.id,
    parent_id: nil
  )

  registry_card = find_registry_card(identifier)
  return nil unless registry_card

  card_definition = build_virtual_card_definition(registry_card, resource)
  return nil unless card_definition

  record = resource.klass.find(record_id)
  result = ::HasHelpers::Cards::CardDataCommand.call_with_definition(
    resource_id:     resource,
    card_definition: card_definition,
    record:          record
  )

  {
    application: app.name,
    card:        result.card,
    fields:      result.fields,
    entries:     result.entries
  }
end