Class: Graphiti::Renderer
Constant Summary collapse
- CONTENT_TYPE =
"application/vnd.api+json"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Class Method Summary collapse
Instance Method Summary collapse
- #as_graphql ⇒ Object
- #as_json ⇒ Object
-
#initialize(proxy, options) ⇒ Renderer
constructor
A new instance of Renderer.
- #records ⇒ Object
- #to_graphql ⇒ Object
- #to_json ⇒ Object
-
#to_jsonapi ⇒ Object
JSON:API requires the key even when the include turns up nothing.
- #to_xml ⇒ Object
Constructor Details
#initialize(proxy, options) ⇒ Renderer
Returns a new instance of Renderer.
7 8 9 10 |
# File 'lib/graphiti/renderer.rb', line 7 def initialize(proxy, ) @proxy = proxy @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/graphiti/renderer.rb', line 5 def @options end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
5 6 7 |
# File 'lib/graphiti/renderer.rb', line 5 def proxy @proxy end |
Class Method Details
.graphql_renderer(proxy) ⇒ Object
53 54 55 56 |
# File 'lib/graphiti/renderer.rb', line 53 def self.graphql_renderer(proxy) implementation = Graphiti::HashRenderer.new(proxy.resource, graphql: true) JSONAPI::Serializable::Renderer.new(implementation) end |
.hash_renderer(proxy) ⇒ Object
48 49 50 51 |
# File 'lib/graphiti/renderer.rb', line 48 def self.hash_renderer(proxy) implementation = Graphiti::HashRenderer.new(proxy.resource) JSONAPI::Serializable::Renderer.new(implementation) end |
.jsonapi_renderer ⇒ Object
43 44 45 46 |
# File 'lib/graphiti/renderer.rb', line 43 def self.jsonapi_renderer @jsonapi_renderer ||= JSONAPI::Serializable::Renderer .new(JSONAPI::Renderer.new) end |
Instance Method Details
#as_graphql ⇒ Object
23 24 25 |
# File 'lib/graphiti/renderer.rb', line 23 def as_graphql render(self.class.graphql_renderer(@proxy)) end |
#as_json ⇒ Object
35 36 37 |
# File 'lib/graphiti/renderer.rb', line 35 def as_json render(self.class.hash_renderer(@proxy)) end |
#records ⇒ Object
12 13 14 |
# File 'lib/graphiti/renderer.rb', line 12 def records @records ||= @proxy.data end |
#to_graphql ⇒ Object
27 28 29 |
# File 'lib/graphiti/renderer.rb', line 27 def to_graphql as_graphql.to_json end |
#to_json ⇒ Object
31 32 33 |
# File 'lib/graphiti/renderer.rb', line 31 def to_json as_json.to_json end |
#to_jsonapi ⇒ Object
JSON:API requires the key even when the include turns up nothing.
17 18 19 20 21 |
# File 'lib/graphiti/renderer.rb', line 17 def to_jsonapi rendered = render(self.class.jsonapi_renderer) rendered[:included] ||= [] if proxy.query.includes_requested? rendered.to_json end |
#to_xml ⇒ Object
39 40 41 |
# File 'lib/graphiti/renderer.rb', line 39 def to_xml render(self.class.hash_renderer(@proxy)).to_xml(root: :data) end |