Module: Tibber::Request::GraphQL
- Included in:
- API
- Defined in:
- lib/tibber/request.rb
Overview
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
Instance Method Summary collapse
-
#graphql_call(query, params = nil) ⇒ WrAPI::Request::Entity
Executes a GraphQL query with optional parameters.
Instance Method Details
#graphql_call(query, params = nil) ⇒ WrAPI::Request::Entity
Executes a GraphQL query with optional parameters.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tibber/request.rb', line 27 def graphql_call(query, params = nil) query = (query % params) if params&.any? = { "query": query } result = post('', ) raise GraphQLError.new(result.body['errors']) if result.body['errors'] data = result.body['data'] WrAPI::Request::Entity.create(data['viewer'] || data) rescue Faraday::BadRequestError => e body = e.response[:body] error = body&.dig('errors') || e.to_s raise GraphQLError.new(error) end |