graphiql-rails 1.4.10 → 1.4.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ab0fee7a4101da05c3f03cd30b76c9b63eaf4d8
4
- data.tar.gz: b95201032346b82f334942f597b099db2c5d43a0
3
+ metadata.gz: ff226393a4c410b3b878c08e575263986ce4f74e
4
+ data.tar.gz: 807dae7778cee2858de34d13b195beb64486d5b9
5
5
  SHA512:
6
- metadata.gz: '01860ac1668d7bacc099818f9890ae7cfe25c19471bbc8bfdfd52fa0daf9365f66c86addd3d19d923197bb44e03cd08522e593eb7e5eb377f381cfd41a9b1fd6'
7
- data.tar.gz: 0b0f9b8ef031ab4a636fb16e90e4d1370ad1578619f3c1d5fd1cd06aeef63039b61de098108e7cf88a4108aba6d5bd77da60327ef417f3023e63524945ffcb86
6
+ metadata.gz: 7ad1b9740f79b7598f1c6dd02a53a829dc4f8655f1d5465d469e8fc4641eb1463b321d1948f3309164ffb154c9f69a9d12dade311af136a58014cc4ca13553de
7
+ data.tar.gz: acf71512277755b51e426e8994affa67364c83f9964926806421a557afc70ed57c437aa975d26d5276a2405427a11b6bf00a91269f0097577f43fc432c2a4f36
@@ -1,7 +1,8 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>GraphiQL</title>
4
+ <title><%= GraphiQL::Rails.config.title || 'GraphiQL' %></title>
5
+
5
6
  <%= stylesheet_link_tag("graphiql/rails/application") %>
6
7
  <%= javascript_include_tag("graphiql/rails/application") %>
7
8
  </head>
@@ -60,14 +61,13 @@
60
61
  body: JSON.stringify(graphQLParams),
61
62
  credentials: 'include',
62
63
  }).then(function(response) {
63
- return response.text();
64
- }).then(function(text) {
65
64
  try {
66
- return JSON.parse(text);
65
+ return response.json();
67
66
  } catch(error) {
68
67
  return {
68
+ "status": response.status,
69
69
  "message": "The server responded with invalid JSON, this is probably a server-side error",
70
- "response": text,
70
+ "response": response.text(),
71
71
  };
72
72
  }
73
73
  })
@@ -81,16 +81,21 @@
81
81
 
82
82
  // Render <GraphiQL /> into the body.
83
83
  ReactDOM.render(
84
- React.createElement(GraphiQL, {
85
- fetcher: graphQLFetcher,
86
- defaultQuery: defaultQuery,
87
- <% if GraphiQL::Rails.config.query_params %>
88
- query: parameters.query,
89
- variables: parameters.variables,
90
- onEditQuery: onEditQuery,
91
- onEditVariables: onEditVariables
84
+ React.createElement(GraphiQL,
85
+ {
86
+ fetcher: graphQLFetcher,
87
+ defaultQuery: defaultQuery,
88
+ <% if GraphiQL::Rails.config.query_params %>
89
+ query: parameters.query,
90
+ variables: parameters.variables,
91
+ onEditQuery: onEditQuery,
92
+ onEditVariables: onEditVariables
93
+ <% end %>
94
+ },
95
+ <% if GraphiQL::Rails.config.logo %>
96
+ React.createElement(GraphiQL.Logo, {}, "<%= GraphiQL::Rails.config.logo %>")
92
97
  <% end %>
93
- }),
98
+ ),
94
99
  document.getElementById("graphiql-container")
95
100
  );
96
101
  </script>
@@ -7,7 +7,7 @@ module GraphiQL
7
7
  # @return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are `->(view_context) { ... }` procs to determin values
8
8
  attr_accessor :headers
9
9
 
10
- attr_accessor :query_params, :initial_query, :csrf
10
+ attr_accessor :query_params, :initial_query, :csrf, :title, :logo
11
11
 
12
12
  DEFAULT_HEADERS = {
13
13
  'Content-Type' => ->(_) { 'application/json' },
@@ -17,10 +17,12 @@ module GraphiQL
17
17
  "X-CSRF-Token" => -> (view_context) { view_context.form_authenticity_token }
18
18
  }
19
19
 
20
- def initialize(query_params: false, initial_query: nil, csrf: true, headers: DEFAULT_HEADERS)
20
+ def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS)
21
21
  @query_params = query_params
22
22
  @headers = headers.dup
23
23
  @initial_query = initial_query
24
+ @title = title
25
+ @logo = logo
24
26
  @csrf = csrf
25
27
  end
26
28
 
@@ -1,5 +1,5 @@
1
1
  module GraphiQL
2
2
  module Rails
3
- VERSION = "1.4.10"
3
+ VERSION = "1.4.11"
4
4
  end
5
5
  end
data/readme.md CHANGED
@@ -37,6 +37,8 @@ You can override `GraphiQL::Rails.config` values in an initializer (eg, `config/
37
37
 
38
38
  - `query_params` (boolean, default `false`): if `true`, the GraphQL query string will be persisted the page's query params
39
39
  - `initial_query` (string, default `nil`): if provided, it will be rendered in the query pane for a visitor's first visit
40
+ - `title` (string, default `nil`): if provided, it will be rendered in the page <title> tag
41
+ - `logo` (string, default `nil`): if provided, it will be the text logo
40
42
  - `csrf` (boolean, default `true`): include `X-CSRF-Token` in GraphiQL's HTTP requests
41
43
  - `headers` (hash, `String => Proc`): procs to fetch header values for GraphiQL's HTTP requests, in the form `(view_context) -> { ... }`. For example:
42
44
 
@@ -10,6 +10,8 @@ module GraphiQL
10
10
  teardown do
11
11
  GraphiQL::Rails.config.query_params = false
12
12
  GraphiQL::Rails.config.initial_query = nil
13
+ GraphiQL::Rails.config.title = nil
14
+ GraphiQL::Rails.config.logo = nil
13
15
  GraphiQL::Rails.config.headers = {}
14
16
  end
15
17
 
@@ -35,6 +37,26 @@ module GraphiQL
35
37
  refute_includes(@response.body, '"{ customQuery(id: \"123\") }"')
36
38
  end
37
39
 
40
+ test "it uses title config" do
41
+ GraphiQL::Rails.config.title = 'Custom Title'
42
+ get :show, graphql_params
43
+ assert_includes(@response.body, '<title>Custom Title</title>')
44
+
45
+ GraphiQL::Rails.config.title = nil
46
+ get :show, graphql_params
47
+ assert_includes(@response.body, '<title>GraphiQL</title>')
48
+ end
49
+
50
+ test "it uses logo config" do
51
+ GraphiQL::Rails.config.logo = 'Custom Logo'
52
+ get :show, graphql_params
53
+ assert_includes(@response.body, 'React.createElement(GraphiQL.Logo, {}, "Custom Logo")')
54
+
55
+ GraphiQL::Rails.config.logo = nil
56
+ get :show, graphql_params
57
+ refute_includes(@response.body, 'React.createElement(GraphiQL.Logo, {}, "Custom Logo")')
58
+ end
59
+
38
60
  test "it uses query_params config" do
39
61
  get :show, graphql_params
40
62
  refute_includes(@response.body, "onEditQuery")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiql-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.10
4
+ version: 1.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties