Class: GraphWeaver::Transport::Faraday
- Inherits:
-
Transport
- Object
- Transport
- GraphWeaver::Transport::Faraday
- Defined in:
- lib/graph_weaver/transport/faraday.rb
Overview
Faraday-backed transport. Opt-in (faraday is not a hard dependency):
require "graph_weaver/transport/faraday"
# simplest: build a default connection from a url
GraphWeaver::Transport::Faraday.new("https://api.example.com/graphql")
# customize middleware while building
GraphWeaver::Transport::Faraday.new(url) do |conn|
conn.request :authorization, "Bearer", -> { Tokens.fetch }
conn.response :logger
end
# or bring a fully configured connection
GraphWeaver::Transport::Faraday.new(Faraday.new(url:) { |conn| ... })
Instance Method Summary collapse
-
#initialize(url_or_connection, headers: {}, &block) ⇒ Faraday
constructor
A new instance of Faraday.
Constructor Details
#initialize(url_or_connection, headers: {}, &block) ⇒ Faraday
Returns a new instance of Faraday.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/graph_weaver/transport/faraday.rb', line 32 def initialize(url_or_connection, headers: {}, &block) @connection = case url_or_connection when ::Faraday::Connection url_or_connection else # Faraday appends the default adapter when the block doesn't set one ::Faraday.new(url: url_or_connection, headers:, &block) end @url = @connection.url_prefix.to_s end |