Module: Graphiform::Fields::ClassMethods
- Defined in:
- lib/graphiform/fields.rb
Instance Method Summary collapse
- #graphql_field(name, write_name: nil, readable: true, writable: false, **options) ⇒ Object
- #graphql_fields(*names, **options) ⇒ Object
- #graphql_readable_field(name, **options) ⇒ Object
- #graphql_readable_fields(*names, **options) ⇒ Object
- #graphql_writable_field(name, type: nil, required: false, write_prepare: nil, prepare: nil, description: nil, default_value: ::GraphQL::Schema::Argument::NO_DEFAULT, as: nil, **_options) ⇒ Object
- #graphql_writable_fields(*names, **options) ⇒ Object
Instance Method Details
#graphql_field(name, write_name: nil, readable: true, writable: false, **options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/graphiform/fields.rb', line 56 def graphql_field( name, write_name: nil, readable: true, writable: false, ** ) graphql_readable_field(name, **) if readable graphql_writable_field(write_name || name, **) if writable end |
#graphql_fields(*names, **options) ⇒ Object
67 68 69 70 71 |
# File 'lib/graphiform/fields.rb', line 67 def graphql_fields(*names, **) names.each do |name| graphql_field(name, **) end end |
#graphql_readable_field(name, **options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/graphiform/fields.rb', line 10 def graphql_readable_field( name, ** ) column_def = column(name) association_def = association(name) graphql_add_column_field(name, column_def, **) if column_def.present? graphql_add_association_field(name, association_def, **) if association_def.present? graphql_add_method_field(name, **) unless column_def.present? || association_def.present? graphql_add_scopes_to_filter(name) graphql_field_to_sort(name) end |
#graphql_readable_fields(*names, **options) ⇒ Object
73 74 75 76 77 |
# File 'lib/graphiform/fields.rb', line 73 def graphql_readable_fields(*names, **) names.each do |name| graphql_readable_field(name, **) end end |
#graphql_writable_field(name, type: nil, required: false, write_prepare: nil, prepare: nil, description: nil, default_value: ::GraphQL::Schema::Argument::NO_DEFAULT, as: nil, **_options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/graphiform/fields.rb', line 25 def graphql_writable_field( name, type: nil, required: false, write_prepare: nil, prepare: nil, description: nil, default_value: ::GraphQL::Schema::Argument::NO_DEFAULT, as: nil, ** ) name = name.to_sym argument_name = graphql_resolve_argument_name(name) argument_type = graphql_resolve_argument_type(name, type) return Helpers.logger.warn "Graphiform: Missing `type` for argument #{name}" if argument_type.nil? prepare = write_prepare || prepare graphql_input.class_eval do argument \ argument_name, argument_type, required: required, prepare: prepare, description: description, default_value: default_value, as: as end end |
#graphql_writable_fields(*names, **options) ⇒ Object
79 80 81 82 83 |
# File 'lib/graphiform/fields.rb', line 79 def graphql_writable_fields(*names, **) names.each do |name| graphql_writable_field(name, **) end end |