Class: Jeql::GraphqlBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jeql::GraphqlBlock
- Defined in:
- lib/jeql/graphql_block.rb
Constant Summary collapse
- GraphQlError =
Class.new(Jekyll::Errors::FatalException)
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ GraphqlBlock
constructor
A new instance of GraphqlBlock.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ GraphqlBlock
Returns a new instance of GraphqlBlock.
4 5 6 7 8 |
# File 'lib/jeql/graphql_block.rb', line 4 def initialize(tag_name, text, tokens) super @params = text.strip.split(',').map(&:strip).map{|s| s.gsub(%r!['"]!, '').split(':').map(&:strip)} @text = text end |
Instance Method Details
#render(context) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jeql/graphql_block.rb', line 10 def render(context) hash_params = {} @params.each {|k, v| hash_params[k] = v} endpoint_config = context.registers[:site].config["jeql"][hash_params["endpoint"]] query = Jeql::Query.new(hash_params["query"], context.registers[:site].config["source"], endpoint_config) if query.response.success? context['data'] = JSON.parse(query.response.body)['data'] super else raise GraphQlError, "The query #{query.query_name} failed" end end |