Class: Graphiti::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set defaults



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
55
# File 'lib/graphiti/configuration.rb', line 27

def initialize
  @raise_on_missing_sideload = true
  @concurrency = false
  @respond_to = [:json, :jsonapi, :xml]
  @links_on_demand = false
  @pagination_links_on_demand = false
  @pagination_links = false
  @typecast_reads = true
  @raise_on_missing_sidepost = true
  @cache_rendering = false
  self.debug = ENV.fetch("GRAPHITI_DEBUG", true)
  self.debug_models = ENV.fetch("GRAPHITI_DEBUG_MODELS", false)

  # FIXME: Don't duplicate graphiti-rails efforts
  if defined?(::Rails.root) && (root = ::Rails.root)
    config_file = root.join(".graphiticfg.yml")
    if config_file.exist?
      cfg = YAML.load_file(config_file)
      @schema_path = root.join("public#{cfg["namespace"]}/schema.json")
    else
      @schema_path = root.join("public/schema.json")
    end

    if (logger = ::Rails.logger)
      self.debug = logger.debug? && debug
      Graphiti.logger = logger
    end
  end
end

Instance Attribute Details

#before_sideloadObject

Returns the value of attribute before_sideload.



18
19
20
# File 'lib/graphiti/configuration.rb', line 18

def before_sideload
  @before_sideload
end

#cache_rendering=(value) ⇒ Object (writeonly)

Sets the attribute cache_rendering

Parameters:

  • value

    the value to set the attribute cache_rendering to.



23
24
25
# File 'lib/graphiti/configuration.rb', line 23

def cache_rendering=(value)
  @cache_rendering = value
end

#concurrencyBoolean

Returns Concurrently fetch sideloads? Defaults to false OR if classes are cached (Rails-only).

Returns:

  • (Boolean)

    Concurrently fetch sideloads? Defaults to false OR if classes are cached (Rails-only)



9
10
11
# File 'lib/graphiti/configuration.rb', line 9

def concurrency
  @concurrency
end

#context_for_endpointObject

Returns the value of attribute context_for_endpoint.



12
13
14
# File 'lib/graphiti/configuration.rb', line 12

def context_for_endpoint
  @context_for_endpoint
end

#debugObject

Returns the value of attribute debug.



20
21
22
# File 'lib/graphiti/configuration.rb', line 20

def debug
  @debug
end

#debug_modelsObject

Returns the value of attribute debug_models.



20
21
22
# File 'lib/graphiti/configuration.rb', line 20

def debug_models
  @debug_models
end

Returns the value of attribute links_on_demand.



13
14
15
# File 'lib/graphiti/configuration.rb', line 13

def links_on_demand
  @links_on_demand
end

Returns the value of attribute pagination_links.



15
16
17
# File 'lib/graphiti/configuration.rb', line 15

def pagination_links
  @pagination_links
end

Returns the value of attribute pagination_links_on_demand.



14
15
16
# File 'lib/graphiti/configuration.rb', line 14

def pagination_links_on_demand
  @pagination_links_on_demand
end

#raise_on_missing_sideloadBoolean

Returns Should we raise when the client requests a relationship not defined on the server? Defaults to true.

Returns:

  • (Boolean)

    Should we raise when the client requests a relationship not defined on the server? Defaults to true.



6
7
8
# File 'lib/graphiti/configuration.rb', line 6

def raise_on_missing_sideload
  @raise_on_missing_sideload
end

#raise_on_missing_sidepostObject

Returns the value of attribute raise_on_missing_sidepost.



17
18
19
# File 'lib/graphiti/configuration.rb', line 17

def raise_on_missing_sidepost
  @raise_on_missing_sidepost
end

#respond_toObject

Returns the value of attribute respond_to.



11
12
13
# File 'lib/graphiti/configuration.rb', line 11

def respond_to
  @respond_to
end

#schema_pathObject



67
68
69
# File 'lib/graphiti/configuration.rb', line 67

def schema_path
  @schema_path ||= raise("No schema_path defined! Set Graphiti.config.schema_path to save your schema.")
end

#typecast_readsObject

Returns the value of attribute typecast_reads.



16
17
18
# File 'lib/graphiti/configuration.rb', line 16

def typecast_reads
  @typecast_reads
end

Instance Method Details

#cache_rendering?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
# File 'lib/graphiti/configuration.rb', line 57

def cache_rendering?
  use_caching = @cache_rendering && Graphiti.cache.respond_to?(:fetch)

  use_caching.tap do |use|
    if @cache_rendering && !Graphiti.cache&.respond_to?(:fetch)
      raise "You must configure a cache store in order to use cache_rendering. Set Graphiti.cache = Rails.cache, for example."
    end
  end
end

#with_option(key, value) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/graphiti/configuration.rb', line 81

def with_option(key, value)
  original = send(key)
  send(:"#{key}=", value)
  yield
ensure
  send(:"#{key}=", original)
end