Class: ActiveGraphQL::Model

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/activegraphql/model.rb

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



9
10
11
# File 'lib/activegraphql/model.rb', line 9

def config
  @config
end

Class Method Details

.allObject



40
41
42
# File 'lib/activegraphql/model.rb', line 40

def all
  build_fetcher(name.demodulize.underscore.pluralize.to_sym)
end

.build_fetcher(action, params = nil) ⇒ Object



52
53
54
55
56
57
# File 'lib/activegraphql/model.rb', line 52

def build_fetcher(action, params = nil)
  Fetcher.new(config: configurable_class.config,
              klass: self,
              action: action,
              params: params)
end

.configurable_classObject

Resolves the class who is extending from ActiveGraphql::Model.

This provides the capability for configuring inheritable classes with
specific configuration to the corresponding graphql service.


36
37
38
# File 'lib/activegraphql/model.rb', line 36

def configurable_class
  ancestors[ancestors.find_index(ActiveGraphQL::Model) - 1]
end

.configure(config = {}) ⇒ Object

This provides ability to configure the class inherited from here.

Also field classes will have the configuration.

Example:
  class BaseModelToMyService < ActiveGraphql::Model
    configure url: 'http://localhost:3000/graphql'
  end

  class ModelToMyService < BaseModelToMyService
  end

  BaseModelToMyService.config
  => { url: "http://localhost:3000/graphql" }

  ModelToMyService.url
  => { url: "http://localhost:3000/graphql" }


27
28
29
30
# File 'lib/activegraphql/model.rb', line 27

def configure(config = {})
  configurable_class.config ||= {}
  configurable_class.config.merge!(config)
end

.find_by(conditions = {}) ⇒ Object



48
49
50
# File 'lib/activegraphql/model.rb', line 48

def find_by(conditions = {})
  build_fetcher(name.demodulize.underscore.to_sym, conditions)
end

.where(conditions = {}) ⇒ Object



44
45
46
# File 'lib/activegraphql/model.rb', line 44

def where(conditions = {})
  build_fetcher(name.demodulize.underscore.pluralize.to_sym, conditions)
end