Module: GraphQL::Groups::HasGroups::ClassMethods
- Defined in:
- lib/graphql/groups/has_groups.rb
Instance Attribute Summary collapse
-
#class_scope ⇒ Object
readonly
Returns the value of attribute class_scope.
Instance Method Summary collapse
- #by(name, **options, &block) ⇒ Object
- #group_field(*args, **kwargs, &block) ⇒ Object
- #result_type(&block) ⇒ Object
- #scope(&block) ⇒ Object
Instance Attribute Details
#class_scope ⇒ Object (readonly)
Returns the value of attribute class_scope.
18 19 20 |
# File 'lib/graphql/groups/has_groups.rb', line 18 def class_scope @class_scope end |
Instance Method Details
#by(name, **options, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/graphql/groups/has_groups.rb', line 20 def by(name, **, &block) query_method = [:query_method] || name resolver_method = "resolve_#{query_method}".to_sym group_field name, [own_result_type], query_method: query_method, null: true, resolver_method: resolver_method, **, &block define_method query_method do |**kwargs| kwargs[:scope].group(name) end define_method resolver_method do |**_| group[name] end end |
#group_field(*args, **kwargs, &block) ⇒ Object
39 40 41 42 43 |
# File 'lib/graphql/groups/has_groups.rb', line 39 def group_field(*args, **kwargs, &block) field_defn = field_class.(*args, owner: self, **kwargs, &block) add_field(field_defn) field_defn end |
#result_type(&block) ⇒ Object
45 46 47 |
# File 'lib/graphql/groups/has_groups.rb', line 45 def result_type(&block) @own_result_type = instance_eval(&block) end |
#scope(&block) ⇒ Object
49 50 51 |
# File 'lib/graphql/groups/has_groups.rb', line 49 def scope(&block) @class_scope = block end |