Class: Decidim::GraphiQL::Rails::Config
- Inherits:
-
Object
- Object
- Decidim::GraphiQL::Rails::Config
- Defined in:
- lib/decidim/api/graphiql/config.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ "Content-Type" => ->(_) { "application/json" } }.freeze
- CSRF_TOKEN_HEADER =
{ "X-CSRF-Token" => ->(view_context) { view_context.form_authenticity_token } }.freeze
Instance Attribute Summary collapse
-
#csrf ⇒ Object
Returns the value of attribute csrf.
-
#headers ⇒ Hash<String => Proc>
Keys are headers to include in GraphQL requests, values are ‘->(view_context) { … }` procs to determine values.
-
#initial_query ⇒ Object
Returns the value of attribute initial_query.
-
#logo ⇒ Object
Returns the value of attribute logo.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS) ⇒ Config
constructor
rubocop:disable Metrics/ParameterLists.
-
#resolve_headers(view_context) ⇒ Object
Call defined procs, add CSRF token if specified.
Constructor Details
#initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS) ⇒ Config
rubocop:disable Metrics/ParameterLists
24 25 26 27 28 29 30 31 |
# File 'lib/decidim/api/graphiql/config.rb', line 24 def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS) @query_params = query_params @headers = headers.dup @initial_query = initial_query @title = title @logo = logo @csrf = csrf end |
Instance Attribute Details
#csrf ⇒ Object
Returns the value of attribute csrf.
13 14 15 |
# File 'lib/decidim/api/graphiql/config.rb', line 13 def csrf @csrf end |
#headers ⇒ Hash<String => Proc>
Returns Keys are headers to include in GraphQL requests, values are ‘->(view_context) { … }` procs to determine values.
11 12 13 |
# File 'lib/decidim/api/graphiql/config.rb', line 11 def headers @headers end |
#initial_query ⇒ Object
Returns the value of attribute initial_query.
13 14 15 |
# File 'lib/decidim/api/graphiql/config.rb', line 13 def initial_query @initial_query end |
#logo ⇒ Object
Returns the value of attribute logo.
13 14 15 |
# File 'lib/decidim/api/graphiql/config.rb', line 13 def logo @logo end |
#query_params ⇒ Object
Returns the value of attribute query_params.
13 14 15 |
# File 'lib/decidim/api/graphiql/config.rb', line 13 def query_params @query_params end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/decidim/api/graphiql/config.rb', line 13 def title @title end |
Instance Method Details
#resolve_headers(view_context) ⇒ Object
Call defined procs, add CSRF token if specified
35 36 37 38 39 40 41 42 43 |
# File 'lib/decidim/api/graphiql/config.rb', line 35 def resolve_headers(view_context) all_headers = DEFAULT_HEADERS.merge(headers) all_headers = all_headers.merge(CSRF_TOKEN_HEADER) if csrf all_headers.transform_values do |value| value.call(view_context) end end |