Module: Quail::SchemaBuilder::TypeDefinitions
- Defined in:
- lib/quail/schema_builder/type_definitions.rb
Overview
Helpers for defining fields and arguments on dynamically-built GraphQL types.
Class Method Summary collapse
- .add_arguments(field, arguments) ⇒ Object
- .define_extra_query_fields(type_class, extra_fields) ⇒ Object
- .define_query_fields(type_class, fields) ⇒ Object
- .define_subscription_fields(type_class, fields) ⇒ Object
Class Method Details
.add_arguments(field, arguments) ⇒ Object
37 38 39 40 41 |
# File 'lib/quail/schema_builder/type_definitions.rb', line 37 def self.add_arguments(field, arguments) arguments&.each do |arg_name, arg_config| field.argument arg_name, arg_config[:type], required: arg_config[:required] end end |
.define_extra_query_fields(type_class, extra_fields) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/quail/schema_builder/type_definitions.rb', line 19 def self.define_extra_query_fields(type_class, extra_fields) extra_fields.each do |name, config| f = type_class.field name, config[:type], null: config[:null] add_arguments(f, config[:arguments]) resolver = config[:resolver] type_class.define_method(name) do |**args| resolver.new(object, args, context).call end end end |
.define_query_fields(type_class, fields) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/quail/schema_builder/type_definitions.rb', line 7 def self.define_query_fields(type_class, fields) fields.each do |name, config| f = type_class.field name, config[:type], null: config[:null] add_arguments(f, config[:arguments]) next unless config[:resolve] type_class.define_method(name) do |**args| config[:resolve].call(object, args, context) end end end |
.define_subscription_fields(type_class, fields) ⇒ Object
31 32 33 34 35 |
# File 'lib/quail/schema_builder/type_definitions.rb', line 31 def self.define_subscription_fields(type_class, fields) fields.each do |name, sub_class| type_class.field name, subscription: sub_class end end |