graphiql-rails 1.5.0 → 1.6.0

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: 9e3346833928fea17dbf850ff827492e85fb22de
4
- data.tar.gz: ab244f2fea1ce9600c4ec33bff7d7dc3a6a53b69
3
+ metadata.gz: 6d429f568b6d396fb51add5b421cccec57c1e3e7
4
+ data.tar.gz: 87a72232fc6511e41a2dafa5d28dec603bb2689f
5
5
  SHA512:
6
- metadata.gz: 463a7beb86a17d48c06c06d4392f8cb6978fc868c8ff133c9b4eaae1408f420a49643d10afaf7a25b5f1166a2f6570dd9d54832dc47c6c4f28f3ebb660b4527e
7
- data.tar.gz: 44b00c6354202f42828acbb4e95b5c01d23982e0c839c19c4fd8bdeddd8f9f9cc5414b2bc30c453978828c561d79f26fdca02d901c09c0dcd5b7006c64b456e5
6
+ metadata.gz: dcd7f622dd31a9af902527d30b3de1e3067523c256eca330ed59950ca81c1a6d33d441dd0520905c831fad5a1cd8402dc31d8e9e7b2b612871675b81dd3f703c
7
+ data.tar.gz: bae555bf6ec6e0f086fb41048d4169ce529380d544d7c202c2badbe80f7cae40ea97c10b2f4176d0395f95bfee255c1f4035079798f87a52510bd7c7c284ebf3
@@ -2,3 +2,4 @@
2
2
  //= require ./react-dom-16.6.0
3
3
  //= require ./fetch-0.10.1
4
4
  //= require ./graphiql-0.12.0
5
+ //= require ./graphiql_show
@@ -0,0 +1,91 @@
1
+ document.addEventListener("DOMContentLoaded", function(event) {
2
+ var graphiqlContainer = document.getElementById("graphiql-container");
3
+ var parameters = {};
4
+
5
+ var queryParams = graphiqlContainer.dataset.queryParams;
6
+
7
+ if (queryParams === 'true') {
8
+ // Parse the search string to get url parameters.
9
+ var search = window.location.search;
10
+ search.substr(1).split('&').forEach(function (entry) {
11
+ var eq = entry.indexOf('=');
12
+ if (eq >= 0) {
13
+ parameters[decodeURIComponent(entry.slice(0, eq))] =
14
+ decodeURIComponent(entry.slice(eq + 1));
15
+ }
16
+ });
17
+ // if variables was provided, try to format it.
18
+ if (parameters.variables) {
19
+ try {
20
+ parameters.variables =
21
+ JSON.stringify(JSON.parse(parameters.variables), null, 2);
22
+ } catch (e) {
23
+ // Do nothing, we want to display the invalid JSON as a string, rather
24
+ // than present an error.
25
+ }
26
+ }
27
+ // When the query and variables string is edited, update the URL bar so
28
+ // that it can be easily shared
29
+ function onEditQuery(newQuery) {
30
+ parameters.query = newQuery;
31
+ updateURL();
32
+ }
33
+ function onEditVariables(newVariables) {
34
+ parameters.variables = newVariables;
35
+ updateURL();
36
+ }
37
+ function updateURL() {
38
+ var newSearch = '?' + Object.keys(parameters).map(function (key) {
39
+ return encodeURIComponent(key) + '=' +
40
+ encodeURIComponent(parameters[key]);
41
+ }).join('&');
42
+ history.replaceState(null, null, newSearch);
43
+ }
44
+
45
+ }
46
+
47
+
48
+ // Defines a GraphQL fetcher using the fetch API.
49
+ var graphQLEndpoint = graphiqlContainer.dataset.graphqlEndpointPath;
50
+ function graphQLFetcher(graphQLParams) {
51
+ return fetch(graphQLEndpoint, {
52
+ method: 'post',
53
+ headers: JSON.parse(graphiqlContainer.dataset.headers),
54
+ body: JSON.stringify(graphQLParams),
55
+ credentials: 'include',
56
+ }).then(function(response) {
57
+ try {
58
+ return response.json();
59
+ } catch(error) {
60
+ return {
61
+ "status": response.status,
62
+ "message": "The server responded with invalid JSON, this is probably a server-side error",
63
+ "response": response.text(),
64
+ };
65
+ }
66
+ })
67
+ }
68
+
69
+ var initial_query = graphiqlContainer.dataset.initialQuery;
70
+
71
+ if (initial_query) {
72
+ var defaultQuery = initial_query;
73
+ } else {
74
+ var defaultQuery = undefined;
75
+ }
76
+
77
+
78
+ // Render <GraphiQL /> into the body.
79
+ var element_props = { fetcher: graphQLFetcher, defaultQuery: defaultQuery };
80
+
81
+ if (queryParams === 'true') {
82
+ queryParams = Object.assign({}, queryParams, { query: parameters.query, variables: parameters.variables, onEditQuery: onEditQuery, onEditVariables: onEditVariables });
83
+ }
84
+
85
+ ReactDOM.render(
86
+ React.createElement(GraphiQL, element_props,
87
+ React.createElement(GraphiQL.Logo, {}, graphiqlContainer.dataset.logo)
88
+ ),
89
+ document.getElementById("graphiql-container")
90
+ );
91
+ });
@@ -7,97 +7,12 @@
7
7
  <%= javascript_include_tag("graphiql/rails/application") %>
8
8
  </head>
9
9
  <body>
10
- <div id="graphiql-container">
11
- Loading...
12
- </div>
13
- <script>
14
- var parameters = {};
15
-
16
- <% if GraphiQL::Rails.config.query_params %>
17
- // Parse the search string to get url parameters.
18
- var search = window.location.search;
19
- search.substr(1).split('&').forEach(function (entry) {
20
- var eq = entry.indexOf('=');
21
- if (eq >= 0) {
22
- parameters[decodeURIComponent(entry.slice(0, eq))] =
23
- decodeURIComponent(entry.slice(eq + 1));
24
- }
25
- });
26
- // if variables was provided, try to format it.
27
- if (parameters.variables) {
28
- try {
29
- parameters.variables =
30
- JSON.stringify(JSON.parse(parameters.variables), null, 2);
31
- } catch (e) {
32
- // Do nothing, we want to display the invalid JSON as a string, rather
33
- // than present an error.
34
- }
35
- }
36
- // When the query and variables string is edited, update the URL bar so
37
- // that it can be easily shared
38
- function onEditQuery(newQuery) {
39
- parameters.query = newQuery;
40
- updateURL();
41
- }
42
- function onEditVariables(newVariables) {
43
- parameters.variables = newVariables;
44
- updateURL();
45
- }
46
- function updateURL() {
47
- var newSearch = '?' + Object.keys(parameters).map(function (key) {
48
- return encodeURIComponent(key) + '=' +
49
- encodeURIComponent(parameters[key]);
50
- }).join('&');
51
- history.replaceState(null, null, newSearch);
52
- }
53
- <% end %>
54
-
55
- // Defines a GraphQL fetcher using the fetch API.
56
- var graphQLEndpoint = "<%= graphql_endpoint_path %>";
57
- function graphQLFetcher(graphQLParams) {
58
- return fetch(graphQLEndpoint, {
59
- method: 'post',
60
- headers: <%= raw JSON.pretty_generate(GraphiQL::Rails.config.resolve_headers(self)) %>,
61
- body: JSON.stringify(graphQLParams),
62
- credentials: 'include',
63
- }).then(function(response) {
64
- try {
65
- return response.json();
66
- } catch(error) {
67
- return {
68
- "status": response.status,
69
- "message": "The server responded with invalid JSON, this is probably a server-side error",
70
- "response": response.text(),
71
- };
72
- }
73
- })
74
- }
75
-
76
- <% if GraphiQL::Rails.config.initial_query %>
77
- var defaultQuery = "<%= GraphiQL::Rails.config.initial_query.gsub("\n", '\n').gsub('"', '\"').html_safe %>";
78
- <% else %>
79
- var defaultQuery = undefined
80
- <% end %>
81
-
82
- // Render <GraphiQL /> into the body.
83
- ReactDOM.render(
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 %>")
97
- <% end %>
98
- ),
99
- document.getElementById("graphiql-container")
100
- );
101
- </script>
10
+ <%= content_tag :div, 'Loading...', id: 'graphiql-container', data: {
11
+ graphql_endpoint_path: graphql_endpoint_path,
12
+ initial_query: GraphiQL::Rails.config.initial_query,
13
+ logo: GraphiQL::Rails.config.logo,
14
+ headers: GraphiQL::Rails.config.resolve_headers(self),
15
+ query_params: GraphiQL::Rails.config.query_params
16
+ } %>
102
17
  </body>
103
18
  </html>
@@ -1,5 +1,5 @@
1
1
  module GraphiQL
2
2
  module Rails
3
- VERSION = "1.5.0"
3
+ VERSION = "1.6.0"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  module GraphiQL
4
4
  module Rails
@@ -16,28 +16,27 @@ module GraphiQL
16
16
  end
17
17
 
18
18
  def graphql_params
19
- { params: { graphql_path: "/my/endpoint" } }
19
+ { params: { graphql_path: '/my/endpoint' } }
20
20
  end
21
21
 
22
- test "renders GraphiQL" do
22
+ test 'renders GraphiQL' do
23
23
  get :show, graphql_params
24
24
  assert_response(:success)
25
- assert_includes(@response.body, "React.createElement(GraphiQL", "it renders GraphiQL")
26
- assert_includes(@response.body, "my/endpoint", "it uses the provided path")
27
- assert_match(/application-\w+\.js/, @response.body, "it includes assets")
25
+ assert_includes(@response.body, 'my/endpoint', 'it uses the provided path')
26
+ assert_match(/application-\w+\.js/, @response.body, 'it includes assets')
28
27
  end
29
28
 
30
- test "it uses initial_query config" do
29
+ test 'it uses initial_query config' do
31
30
  GraphiQL::Rails.config.initial_query = '{ customQuery(id: "123") }'
32
31
  get :show, graphql_params
33
- assert_includes(@response.body, '"{ customQuery(id: \"123\") }"')
32
+ assert_includes(@response.body, '"{ customQuery(id: &quot;123&quot;) }"')
34
33
 
35
34
  GraphiQL::Rails.config.initial_query = nil
36
35
  get :show, graphql_params
37
- refute_includes(@response.body, '"{ customQuery(id: \"123\") }"')
36
+ refute_includes(@response.body, '"{ customQuery(id: &quot;123&quot;) }"')
38
37
  end
39
38
 
40
- test "it uses title config" do
39
+ test 'it uses title config' do
41
40
  GraphiQL::Rails.config.title = 'Custom Title'
42
41
  get :show, graphql_params
43
42
  assert_includes(@response.body, '<title>Custom Title</title>')
@@ -47,30 +46,30 @@ module GraphiQL
47
46
  assert_includes(@response.body, '<title>GraphiQL</title>')
48
47
  end
49
48
 
50
- test "it uses logo config" do
49
+ test 'it uses logo config' do
51
50
  GraphiQL::Rails.config.logo = 'Custom Logo'
52
51
  get :show, graphql_params
53
- assert_includes(@response.body, 'React.createElement(GraphiQL.Logo, {}, "Custom Logo")')
52
+ assert_includes(@response.body, %(data-logo="Custom Logo"))
54
53
 
55
54
  GraphiQL::Rails.config.logo = nil
56
55
  get :show, graphql_params
57
- refute_includes(@response.body, 'React.createElement(GraphiQL.Logo, {}, "Custom Logo")')
56
+ refute_includes(@response.body, %(data-logo="Custom Logo"))
58
57
  end
59
58
 
60
- test "it uses query_params config" do
59
+ test 'it uses query_params config' do
61
60
  get :show, graphql_params
62
- refute_includes(@response.body, "onEditQuery")
61
+ assert_includes(@response.body, %(data-query-params="false"))
63
62
 
64
63
  GraphiQL::Rails.config.query_params = true
65
64
  get :show, graphql_params
66
- assert_includes(@response.body, "onEditQuery")
65
+ assert_includes(@response.body, %(data-query-params="true"))
67
66
  end
68
67
 
69
- test "it renders headers" do
70
- GraphiQL::Rails.config.headers["Nonsense-Header"] = -> (view_ctx) { "Value" }
68
+ test 'it renders headers' do
69
+ GraphiQL::Rails.config.headers['Nonsense-Header'] = ->(_view_ctx) { 'Value' }
71
70
  get :show, graphql_params
72
- assert_includes(@response.body, %|"Nonsense-Header": "Value"|)
73
- assert_includes(@response.body, %|"X-CSRF-Token": "|)
71
+ assert_includes(@response.body, %(&quot;Nonsense-Header&quot;:&quot;Value&quot;))
72
+ assert_includes(@response.body, %(&quot;X-CSRF-Token&quot;:&quot;))
74
73
  end
75
74
  end
76
75
  end
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.5.0
4
+ version: 1.6.0
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-11-06 00:00:00.000000000 Z
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -147,6 +147,7 @@ files:
147
147
  - app/assets/javascripts/graphiql/rails/application.js
148
148
  - app/assets/javascripts/graphiql/rails/fetch-0.10.1.js
149
149
  - app/assets/javascripts/graphiql/rails/graphiql-0.12.0.js
150
+ - app/assets/javascripts/graphiql/rails/graphiql_show.js
150
151
  - app/assets/javascripts/graphiql/rails/react-16.6.0.js
151
152
  - app/assets/javascripts/graphiql/rails/react-dom-16.6.0.js
152
153
  - app/assets/stylesheets/graphiql/rails/application.css