Class: GraphitiGraphQL::GraphitiSchema::Resource
- Inherits:
-
Object
- Object
- GraphitiGraphQL::GraphitiSchema::Resource
- Defined in:
- lib/graphiti_graphql/graphiti_schema/resource.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #all_attributes ⇒ Object
- #attributes ⇒ Object
- #children ⇒ Object
- #extra_attributes ⇒ Object
- #filters ⇒ Object
- #graphql_class_name(allow_interface = true) ⇒ Object
- #graphql_entrypoint ⇒ Object
-
#initialize(schema, config) ⇒ Resource
constructor
A new instance of Resource.
- #name ⇒ Object
- #pbt?(name) ⇒ Boolean
- #polymorphic? ⇒ Boolean
- #related_resource(relationship_name) ⇒ Object
- #relationships ⇒ Object
- #remote? ⇒ Boolean
- #remote_url ⇒ Object
- #sideloads ⇒ Object
- #sorts ⇒ Object
- #stats ⇒ Object
- #type ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 4 def config @config end |
#schema ⇒ Object (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_attributes ⇒ Object
98 99 100 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 98 def all_attributes attributes.merge(extra_attributes) end |
#attributes ⇒ Object
94 95 96 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 94 def attributes config[:attributes] end |
#children ⇒ Object
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_attributes ⇒ Object
90 91 92 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 90 def extra_attributes config[:extra_attributes] end |
#filters ⇒ Object
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_entrypoint ⇒ Object
74 75 76 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 74 def graphql_entrypoint config[:graphql_entrypoint] end |
#name ⇒ Object
62 63 64 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 62 def name config[:name] end |
#pbt?(name) ⇒ 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
44 45 46 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 44 def polymorphic? !!config[:polymorphic] end |
#related_resource(relationship_name) ⇒ Object
35 36 37 38 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 35 def (relationship_name) resource_name = relationships[relationship_name][:resource] schema.get_resource(resource_name) end |
#relationships ⇒ Object
86 87 88 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 86 def relationships config[:relationships] end |
#remote? ⇒ Boolean
58 59 60 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 58 def remote? !!config[:remote] end |
#remote_url ⇒ Object
54 55 56 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 54 def remote_url config[:remote] end |
#sideloads ⇒ Object
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 |
#sorts ⇒ Object
78 79 80 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 78 def sorts config[:sorts] end |
#stats ⇒ Object
66 67 68 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 66 def stats config[:stats] end |
#type ⇒ Object
70 71 72 |
# File 'lib/graphiti_graphql/graphiti_schema/resource.rb', line 70 def type config[:type] end |