Skip to content

Commit

Permalink
Merge pull request #107 from pachkovsky/master
Browse files Browse the repository at this point in the history
add inputValueDeprecation flag to be able to introspect deprecated arguments
  • Loading branch information
rmosolgo committed Feb 23, 2024
2 parents f47d940 + 41a73f4 commit e7bfd39
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/assets/javascripts/graphiql/rails/graphiql_show.js
Expand Up @@ -77,7 +77,12 @@ document.addEventListener("DOMContentLoaded", function(event) {


// Render <GraphiQL /> into the body.
var elementProps = { fetcher: graphQLFetcher, defaultQuery: defaultQuery, headerEditorEnabled: graphiqlContainer.dataset.headerEditorEnabled === 'true' };
var elementProps = {
fetcher: graphQLFetcher,
defaultQuery: defaultQuery,
headerEditorEnabled: graphiqlContainer.dataset.headerEditorEnabled === 'true',
inputValueDeprecation: graphiqlContainer.dataset.inputValueDeprecation === 'true',
};

Object.assign(elementProps, { query: parameters.query, variables: parameters.variables })
if (queryParams === 'true') {
Expand Down
3 changes: 2 additions & 1 deletion app/views/graphiql/rails/editors/show.html.erb
Expand Up @@ -13,7 +13,8 @@
logo: GraphiQL::Rails.config.logo,
headers: GraphiQL::Rails.config.resolve_headers(self),
query_params: GraphiQL::Rails.config.query_params,
header_editor_enabled: GraphiQL::Rails.config.header_editor_enabled
header_editor_enabled: GraphiQL::Rails.config.header_editor_enabled,
input_value_deprecation: GraphiQL::Rails.config.input_value_deprecation
} %>
</body>
</html>
5 changes: 3 additions & 2 deletions lib/graphiql/rails/config.rb
Expand Up @@ -7,7 +7,7 @@ class Config
# @return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are `->(view_context) { ... }` procs to determin values
attr_accessor :headers

attr_accessor :query_params, :initial_query, :csrf, :title, :logo, :header_editor_enabled
attr_accessor :query_params, :initial_query, :csrf, :title, :logo, :header_editor_enabled, :input_value_deprecation

DEFAULT_HEADERS = {
'Content-Type' => ->(_) { 'application/json' },
Expand All @@ -17,13 +17,14 @@ class Config
"X-CSRF-Token" => -> (view_context) { view_context.form_authenticity_token }
}

def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS)
def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS, input_value_deprecation: false)
@query_params = query_params
@headers = headers.dup
@initial_query = initial_query
@title = title
@logo = logo
@csrf = csrf
@input_value_deprecation = input_value_deprecation
end

# Call defined procs, add CSRF token if specified
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -63,7 +63,7 @@ You can override `GraphiQL::Rails.config` values in an initializer (eg, `config/
- `csrf` (boolean, default `true`): include `X-CSRF-Token` in GraphiQL's HTTP requests
- `header_editor_enabled` (boolean, default `false`): if provided, the header editor will be rendered
- `headers` (hash, `String => Proc`): procs to fetch header values for GraphiQL's HTTP requests, in the form `(view_context) -> { ... }`. For example:

- `input_value_deprecation` (boolean, default `false`): if provided, the deprecated arguments will be rendered

```ruby
GraphiQL::Rails.config.headers['Authorization'] = -> (context) { "bearer #{context.cookies['_graphql_token']}" }
Expand Down

0 comments on commit e7bfd39

Please sign in to comment.