Module: SearchObject::Plugin::Graphql::ClassMethods
- Defined in:
- lib/search_object/plugin/graphql.rb
Constant Summary collapse
- KEYS =
%i[type default description required].freeze
Instance Method Summary collapse
-
#accessible?(_context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver.
-
#arguments ⇒ Object
NOTE(rstankov): Used for GraphQL::Function.
-
#authorized?(_object, _context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver.
-
#call(object, args, context) ⇒ Object
NOTE(rstankov): GraphQL::Function interface (deprecated in favour of GraphQL::Schema::Resolver) Documentation - graphql-ruby.org/guides.
- #complexity(value = :default) ⇒ Object
- #deprecation_reason(value = :default) ⇒ Object
- #description(value = :default) ⇒ Object
-
#field_options ⇒ Object
NOTE(rstankov): Used for GraphQL::Schema::Resolver.
- #option(name, options = {}, &block) ⇒ Object
- #type(value = :default, null: true, &block) ⇒ Object
-
#types ⇒ Object
NOTE(rstankov): Used for GraphQL::Function.
-
#visible?(_context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver.
Instance Method Details
#accessible?(_context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver
127 128 129 |
# File 'lib/search_object/plugin/graphql.rb', line 127 def accessible?(_context) true end |
#arguments ⇒ Object
NOTE(rstankov): Used for GraphQL::Function
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/search_object/plugin/graphql.rb', line 80 def arguments (config[:arguments] || {}).inject({}) do |acc, (name, )| argument = GraphQL::Argument.new argument.name = name.to_s argument.type = .fetch(:type) { raise MissingTypeDefinitionError, name } argument.default_value = [:default] if .key? :default argument.description = [:description] if .key? :description acc[name] = argument acc end end |
#authorized?(_object, _context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver
132 133 134 |
# File 'lib/search_object/plugin/graphql.rb', line 132 def (_object, _context) true end |
#call(object, args, context) ⇒ Object
NOTE(rstankov): GraphQL::Function interface (deprecated in favour of GraphQL::Schema::Resolver) Documentation - graphql-ruby.org/guides
70 71 72 |
# File 'lib/search_object/plugin/graphql.rb', line 70 def call(object, args, context) new(filters: args.to_h, object: object, context: context).results end |
#complexity(value = :default) ⇒ Object
50 51 52 53 54 |
# File 'lib/search_object/plugin/graphql.rb', line 50 def complexity(value = :default) return config[:complexity] || 1 if value == :default config[:complexity] = value end |
#deprecation_reason(value = :default) ⇒ Object
62 63 64 65 66 |
# File 'lib/search_object/plugin/graphql.rb', line 62 def deprecation_reason(value = :default) return config[:deprecation_reason] if value == :default config[:deprecation_reason] = value end |
#description(value = :default) ⇒ Object
56 57 58 59 60 |
# File 'lib/search_object/plugin/graphql.rb', line 56 def description(value = :default) return config[:description] if value == :default config[:description] = value end |
#field_options ⇒ Object
NOTE(rstankov): Used for GraphQL::Schema::Resolver
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/search_object/plugin/graphql.rb', line 94 def { type: type, description: description, extras: [], resolver_method: :resolve_with_support, resolver_class: self, deprecation_reason: deprecation_reason, arguments: (config[:arguments] || {}).inject({}) do |acc, (name, )| name = name.to_s.split('_').map(&:capitalize).join name[0] = name[0].downcase acc[name] = ::GraphQL::Schema::Argument.new( name: name.to_s, type: .fetch(:type) { raise MissingTypeDefinitionError, name }, description: [:description], required: !![:required], default_value: .fetch(:default) { ::GraphQL::Schema::Argument::NO_DEFAULT }, owner: self ) acc end, null: !!config[:null], complexity: complexity } end |
#option(name, options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/search_object/plugin/graphql.rb', line 30 def option(name, = {}, &block) config[:arguments] ||= {} config[:arguments][name.to_s] = KEYS.inject({}) do |acc, key| acc[key] = [key] if .key?(key) acc end type = .fetch(:type) { raise MissingTypeDefinitionError, name } [:enum] = type.values.map { |value, enum_value| enum_value.value || value } if type.respond_to?(:values) super(name, , &block) end |
#type(value = :default, null: true, &block) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/search_object/plugin/graphql.rb', line 43 def type(value = :default, null: true, &block) return config[:type] if value == :default && !block_given? config[:type] = block_given? ? GraphQL::ObjectType.define(&block) : value config[:null] = null end |
#types ⇒ Object
NOTE(rstankov): Used for GraphQL::Function
75 76 77 |
# File 'lib/search_object/plugin/graphql.rb', line 75 def types GraphQL::Define::TypeDefiner.instance end |
#visible?(_context) ⇒ Boolean
NOTE(rstankov): Used for GraphQL::Schema::Resolver
122 123 124 |
# File 'lib/search_object/plugin/graphql.rb', line 122 def visible?(_context) true end |