Class: ActiveAdmin::GraphQL::ResourceDefinitionDSL
- Inherits:
-
Object
- Object
- ActiveAdmin::GraphQL::ResourceDefinitionDSL
- Defined in:
- lib/active_admin/graphql/resource_definition_dsl.rb
Overview
DSL for graphql do … end inside ActiveAdmin.register.
Instance Method Summary collapse
-
#batch_action_mutation(&block) ⇒ Object
Pair
typeandresolveforposts_batch_action(graphql-ruby-style block). - #batch_action_run_action_payload_type(type) ⇒ Object
- #collection_action_mutation(name = nil, &block) ⇒ Object
- #collection_action_run_action_payload_type(type) ⇒ Object
- #configure(&block) ⇒ Object
- #disable! ⇒ Object
- #except(*attrs) ⇒ Object (also: #exclude)
-
#initialize(config) ⇒ ResourceDefinitionDSL
constructor
A new instance of ResourceDefinitionDSL.
-
#member_action_mutation(name = nil, &block) ⇒ Object
With no name: configures the aggregate posts_member_action(action: …) field.
- #member_action_run_action_payload_type(type) ⇒ Object
- #only(*attrs) ⇒ Object
- #resolve_batch_action(&block) ⇒ Object
- #resolve_collection_action(&block) ⇒ Object
- #resolve_create(&block) ⇒ Object
- #resolve_destroy(&block) ⇒ Object
-
#resolve_index(&block) ⇒ Object
(also: #resolve_collection)
Override the list field resolver (
posts, etc.). - #resolve_member_action(&block) ⇒ Object
-
#resolve_show(&block) ⇒ Object
(also: #resolve_member)
Override the singular field resolver (
post,registered_resourcefor this type). - #resolve_update(&block) ⇒ Object
-
#run_action_payload_type(type) ⇒ Object
Default return type for all run-action fields unless a kind-specific
typeis set insidebatch_action_mutation/member_action_mutation/collection_action_mutation. - #type_name(name) ⇒ Object
Constructor Details
#initialize(config) ⇒ ResourceDefinitionDSL
Returns a new instance of ResourceDefinitionDSL.
10 11 12 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#batch_action_mutation(&block) ⇒ Object
Pair type and resolve for posts_batch_action (graphql-ruby-style block).
77 78 79 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 77 def batch_action_mutation(&block) RunActionMutationDSL.new(@config.batch_run_action).instance_exec(&block) end |
#batch_action_run_action_payload_type(type) ⇒ Object
101 102 103 104 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 101 def batch_action_run_action_payload_type(type) RunActionMutationConfig.ensure_graphql_object_subclass!(type) @config.batch_run_action.payload_type = type end |
#collection_action_mutation(name = nil, &block) ⇒ Object
89 90 91 92 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 89 def collection_action_mutation(name = nil, &block) cfg = name.nil? ? @config.collection_run_action : @config.collection_action_mutation_for(name) RunActionMutationDSL.new(cfg).instance_exec(&block) end |
#collection_action_run_action_payload_type(type) ⇒ Object
111 112 113 114 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 111 def collection_action_run_action_payload_type(type) RunActionMutationConfig.ensure_graphql_object_subclass!(type) @config.collection_run_action.payload_type = type end |
#configure(&block) ⇒ Object
31 32 33 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 31 def configure(&block) @config.extension_block = block end |
#disable! ⇒ Object
14 15 16 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 14 def disable! @config.enabled = false end |
#except(*attrs) ⇒ Object Also known as: exclude
26 27 28 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 26 def except(*attrs) @config.exclude_attributes.concat(attrs.flatten.map(&:to_sym)) end |
#member_action_mutation(name = nil, &block) ⇒ Object
With no name: configures the aggregate posts_member_action(action: …) field. With a symbol/string: configures posts_member_<action> (one field per member_action), so each action can use its own type, resolve, arguments, and GraphQL inputs.
84 85 86 87 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 84 def member_action_mutation(name = nil, &block) cfg = name.nil? ? @config.member_run_action : @config.member_action_mutation_for(name) RunActionMutationDSL.new(cfg).instance_exec(&block) end |
#member_action_run_action_payload_type(type) ⇒ Object
106 107 108 109 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 106 def member_action_run_action_payload_type(type) RunActionMutationConfig.ensure_graphql_object_subclass!(type) @config.member_run_action.payload_type = type end |
#only(*attrs) ⇒ Object
22 23 24 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 22 def only(*attrs) @config.only_attributes = attrs.flatten.map(&:to_sym) end |
#resolve_batch_action(&block) ⇒ Object
62 63 64 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 62 def resolve_batch_action(&block) @config.batch_run_action.resolve_proc = block end |
#resolve_collection_action(&block) ⇒ Object
72 73 74 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 72 def resolve_collection_action(&block) @config.collection_run_action.resolve_proc = block end |
#resolve_create(&block) ⇒ Object
49 50 51 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 49 def resolve_create(&block) @config.resolve_create_proc = block end |
#resolve_destroy(&block) ⇒ Object
57 58 59 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 57 def resolve_destroy(&block) @config.resolve_destroy_proc = block end |
#resolve_index(&block) ⇒ Object Also known as: resolve_collection
Override the list field resolver (posts, etc.). Must return an ActiveRecord::Relation (or compatible with the connection type). Same auth and ResourceQueryProxy as the default.
37 38 39 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 37 def resolve_index(&block) @config.resolve_index_proc = block end |
#resolve_member_action(&block) ⇒ Object
67 68 69 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 67 def resolve_member_action(&block) @config.member_run_action.resolve_proc = block end |
#resolve_show(&block) ⇒ Object Also known as: resolve_member
Override the singular field resolver (post, registered_resource for this type). Must return a record instance or nil.
44 45 46 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 44 def resolve_show(&block) @config.resolve_show_proc = block end |
#resolve_update(&block) ⇒ Object
53 54 55 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 53 def resolve_update(&block) @config.resolve_update_proc = block end |
#run_action_payload_type(type) ⇒ Object
Default return type for all run-action fields unless a kind-specific type is set inside batch_action_mutation / member_action_mutation / collection_action_mutation.
96 97 98 99 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 96 def run_action_payload_type(type) RunActionMutationConfig.ensure_graphql_object_subclass!(type) @config.run_action_payload_type = type end |
#type_name(name) ⇒ Object
18 19 20 |
# File 'lib/active_admin/graphql/resource_definition_dsl.rb', line 18 def type_name(name) @config.graphql_type_name = name.to_s end |