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 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/groups/has_groups.rb', line 39 def group_field(*args, **kwargs, &block) if args.any? name_arg = args.shift type_arg = args.shift desc_arg = args.shift kwargs[:name] ||= name_arg kwargs[:type] ||= type_arg if type_arg kwargs[:description] ||= desc_arg if desc_arg end field_defn = field_class.new(owner: self, **kwargs, &block) add_field(field_defn) field_defn end |
#result_type(&block) ⇒ Object
55 56 57 |
# File 'lib/graphql/groups/has_groups.rb', line 55 def result_type(&block) @own_result_type = instance_eval(&block) end |
#scope(&block) ⇒ Object
59 60 61 |
# File 'lib/graphql/groups/has_groups.rb', line 59 def scope(&block) @class_scope = block end |