Class: GraphitiGraphQL::GraphitiSchema::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_graphql/graphiti_schema/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, config) ⇒ Resource

Returns a new instance of Resource.



10
11
12
13
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 10

def initialize(schema, config)
  @schema = schema
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 4

def config
  @config
end

#schemaObject (readonly)

Returns the value of attribute schema.



4
5
6
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 4

def schema
  @schema
end

Class Method Details

.gql_name(name) ⇒ Object



6
7
8
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 6

def self.gql_name(name)
  Graphiti::Util::Class.graphql_type_name(name)
end

Instance Method Details

#all_attributesObject



98
99
100
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 98

def all_attributes
  attributes.merge(extra_attributes)
end

#attributesObject



94
95
96
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 94

def attributes
  config[:attributes]
end

#childrenObject



48
49
50
51
52
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 48

def children
  config[:children].map do |name|
    schema.get_resource(name)
  end
end

#extra_attributesObject



90
91
92
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 90

def extra_attributes
  config[:extra_attributes]
end

#filtersObject



82
83
84
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 82

def filters
  config[:filters]
end

#graphql_class_name(allow_interface = true) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 15

def graphql_class_name(allow_interface = true)
  class_name = self.class.gql_name(name)
  if allow_interface
    if polymorphic? && !children.map(&:name).include?(name)
      class_name = "I#{class_name}"
    end
  end
  class_name
end

#graphql_entrypointObject



74
75
76
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 74

def graphql_entrypoint
  config[:graphql_entrypoint]
end

#nameObject



62
63
64
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 62

def name
  config[:name]
end

#pbt?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 40

def pbt?(name)
  relationships[name][:type] == "polymorphic_belongs_to"
end

#polymorphic?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 44

def polymorphic?
  !!config[:polymorphic]
end


35
36
37
38
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 35

def related_resource(relationship_name)
  resource_name = relationships[relationship_name][:resource]
  schema.get_resource(resource_name)
end

#relationshipsObject



86
87
88
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 86

def relationships
  config[:relationships]
end

#remote?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 58

def remote?
  !!config[:remote]
end

#remote_urlObject



54
55
56
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 54

def remote_url
  config[:remote]
end

#sideloadsObject



25
26
27
28
29
30
31
32
33
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 25

def sideloads
  @sideloads ||= {}.tap do |sideloads|
    config[:relationships].each_pair do |k, v|
      sideload = Sideload.new(schema, v)
      sideload.name = k
      sideloads[k] = sideload
    end
  end
end

#sortsObject



78
79
80
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 78

def sorts
  config[:sorts]
end

#statsObject



66
67
68
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 66

def stats
  config[:stats]
end

#typeObject



70
71
72
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 70

def type
  config[:type]
end