decidim-api 0.24.0 → 0.25.0.rc1

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
  SHA256:
3
- metadata.gz: dec8b6a402bb2be545b69809d6e05dc2979ba67e83d25ff858d2c9ba02a08981
4
- data.tar.gz: 15fa13b5aeda25259ae58fd23199d4df6a14c918690f5c69d92f215e63837899
3
+ metadata.gz: 770bc3bb80ff9614494c1ec41f5578049a38bc1f32b127620a679870485c471f
4
+ data.tar.gz: 06e68463c60e2d24b8e6c6c73116a8655729829ae471ed897acb0dac0b204bcf
5
5
  SHA512:
6
- metadata.gz: 150194286368c2a736c6c214655df39769759c3c22b831e35e68b825362866e5af6f5e9174346587d784b441032326fa8156a06d28fa1b2f3831f3622392ad08
7
- data.tar.gz: 9790b1424eb5aecff273d306ebc89cfeea7b1a569d8e3826e9772d5f320baf6b0daaed798e4626e9c4d467a61e1d7b0a0b4bc094daf41b401adcde926ea0594d
6
+ metadata.gz: 9d53db17a10497edbf7151b568d0a2317af1478e13d92caa39e164dbb4db88c0b60d23721823c309c1e0cc28007c5b93a0bcf66da91418963f14814b0230eb0b
7
+ data.tar.gz: 2a3222f93141bb298f39f5fdcaeaa235c3393759ef8e937fdbeee619e291e68841f889a06b91174f4ace90c73e28b39743bbf83525dfd80a1c7ece8852d5a0a6
@@ -4,12 +4,15 @@ module Decidim
4
4
  module Api
5
5
  # Controller to serve the GraphiQL client. Used so that we can hook the
6
6
  # `ForceAuthentication` module.
7
- class GraphiQLController < ::GraphiQL::Rails::EditorsController
7
+ class GraphiQLController < Api::ApplicationController
8
8
  include NeedsOrganization
9
9
  include ForceAuthentication
10
10
 
11
- def self.controller_path
12
- "graphiql/rails/editors"
11
+ def show; end
12
+
13
+ helper_method :graphql_endpoint_path
14
+ def graphql_endpoint_path
15
+ params[:graphql_path]
13
16
  end
14
17
  end
15
18
  end
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable react/jsx-no-undef */
2
2
 
3
- // = require jquery3
4
- // = require decidim/api/react
5
- // = require decidim/api/react-dom
6
- // = require decidim/api/graphql-docs
3
+ import jQuery from "jquery"
4
+ import { render } from "react-dom"
5
+ import { GraphQLDocs } from "graphql-docs"
6
+ import "stylesheets/decidim/api/docs.scss"
7
7
 
8
8
  const fetcherFactory = (path) => {
9
9
  return (query) => {
@@ -18,8 +18,9 @@ const fetcherFactory = (path) => {
18
18
  }
19
19
 
20
20
  window.renderDocumentation = (path) => {
21
- ReactDOM.render(
22
- <GraphQLDocs.GraphQLDocs fetcher={fetcherFactory(path)} />,
21
+ render(
22
+ <GraphQLDocs fetcher={fetcherFactory(path)} />,
23
23
  document.getElementById("documentation"),
24
24
  );
25
25
  };
26
+
@@ -0,0 +1,90 @@
1
+ /* eslint-disable require-jsdoc */
2
+
3
+ import "entrypoints/decidim_api_graphiql.scss";
4
+
5
+ import React from "react";
6
+ import ReactDOM from "react-dom";
7
+
8
+ import GraphiQL from "graphiql";
9
+ import Configuration from "src/decidim/configuration"
10
+
11
+ window.Decidim = window.Decidim || {};
12
+ window.Decidim.config = new Configuration()
13
+
14
+ let parameters = {};
15
+
16
+ // Parse the search string to get url parameters.
17
+ const search = window.location.search;
18
+ search.substr(1).split("&").forEach(function (entry) {
19
+ let eq = entry.indexOf("=");
20
+ if (eq >= 0) {
21
+ parameters[decodeURIComponent(entry.slice(0, eq))] =
22
+ decodeURIComponent(entry.slice(eq + 1));
23
+ }
24
+ });
25
+ // if variables was provided, try to format it.
26
+ if (parameters.variables) {
27
+ try {
28
+ parameters.variables =
29
+ JSON.stringify(JSON.parse(parameters.variables), null, 2);
30
+ } catch (error) {
31
+ // Do nothing, we want to display the invalid JSON as a string, rather
32
+ // than present an error.
33
+ }
34
+ }
35
+
36
+ const updateURL = function() {
37
+ const newSearch = Object.keys(parameters).map(function (key) {
38
+ return `${encodeURIComponent(key)}=${encodeURIComponent(parameters[key])}`;
39
+ }).join("&");
40
+
41
+ history.replaceState(null, null, `?${newSearch}`);
42
+ }
43
+
44
+ // When the query and variables string is edited, update the URL bar so
45
+ // that it can be easily shared
46
+ const onEditQuery = function(newQuery) {
47
+ parameters.query = newQuery;
48
+ updateURL();
49
+ }
50
+
51
+ const onEditVariables = function(newVariables) {
52
+ parameters.variables = newVariables;
53
+ updateURL();
54
+ }
55
+
56
+ // Defines a GraphQL fetcher using the fetch API.
57
+ const graphQLFetcher = function(graphQLParams) {
58
+ const graphQLEndpoint = window.Decidim.config.get("graphql_endpoint");
59
+ return fetch(graphQLEndpoint, {
60
+ method: "post",
61
+ headers: JSON.parse(window.Decidim.config.get("request_headers")),
62
+ body: JSON.stringify(graphQLParams),
63
+ credentials: "include"
64
+ }).then(function(response) {
65
+ try {
66
+ return response.json();
67
+ } catch (error) {
68
+ return {
69
+ "status": response.status,
70
+ "message": "The server responded with invalid JSON, this is probably a server-side error",
71
+ "response": response.text()
72
+ };
73
+ }
74
+ })
75
+ }
76
+
77
+ window.addEventListener("DOMContentLoaded", () => {
78
+ // Render <GraphiQL /> into the body.
79
+ ReactDOM.render(
80
+ React.createElement(GraphiQL, {
81
+ fetcher: graphQLFetcher,
82
+ defaultQuery: window.Decidim.config.get("default_query"),
83
+ query: parameters.query,
84
+ variables: parameters.variables,
85
+ onEditQuery: onEditQuery,
86
+ onEditVariables: onEditVariables
87
+ }),
88
+ document.getElementById("graphiql-container")
89
+ )
90
+ });
@@ -0,0 +1,10 @@
1
+ html,
2
+ body,
3
+ #graphiql-container{
4
+ height: 100%;
5
+ margin: 0;
6
+ overflow: hidden;
7
+ width: 100%;
8
+ }
9
+
10
+ @import "graphiql/graphiql.css";
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= Decidim::GraphiQL::Rails.config.title || "Decidim API" %></title>
5
+ <%= stylesheet_pack_tag("decidim_api_graphiql") %>
6
+ <%= javascript_pack_tag("decidim_api_graphiql") %>
7
+ </head>
8
+ <body>
9
+ <div id="graphiql-container">
10
+ Loading...
11
+ </div>
12
+
13
+ <%
14
+ js_configs = {
15
+ graphql_endpoint: graphql_endpoint_path,
16
+ default_query: Decidim::GraphiQL::Rails.config.initial_query,
17
+ request_headers: JSON.pretty_generate(Decidim::GraphiQL::Rails.config.resolve_headers(self))
18
+ }
19
+ %>
20
+ <script>
21
+ window.Decidim.config.set(<%== js_configs.to_json %>);
22
+ </script>
23
+ </body>
24
+ </html>
@@ -1,8 +1,8 @@
1
1
  <html>
2
2
  <head>
3
3
  <title><%= current_organization.name %> - API Documentation</title>
4
- <%= javascript_include_tag "decidim/api/docs" %>
5
- <%= stylesheet_link_tag "decidim/api/docs" %>
4
+ <%= javascript_pack_tag "decidim_api_docs" %>
5
+ <%= stylesheet_pack_tag "decidim_api_docs" %>
6
6
  <style>
7
7
  </style>
8
8
  </head>
data/config/assets.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ base_path = File.expand_path("..", __dir__)
4
+
5
+ Decidim::Webpacker.register_path("#{base_path}/app/packs")
6
+ Decidim::Webpacker.register_entrypoints(
7
+ decidim_api_docs: "#{base_path}/app/packs/entrypoints/decidim_api_docs.js",
8
+ decidim_api_graphiql: "#{base_path}/app/packs/entrypoints/decidim_api_graphiql.js"
9
+ )
@@ -1,9 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "graphql"
4
- require "graphiql/rails"
5
4
  require "rack/cors"
6
- require "sprockets/es6"
5
+
6
+ require "decidim/core"
7
+ require "decidim/api/graphiql/config"
8
+
9
+ if ActiveSupport::Inflector.method(:inflections).arity.zero?
10
+ # Rails 3 does not take a language in inflections.
11
+ ActiveSupport::Inflector.inflections do |inflect|
12
+ inflect.acronym("GraphiQL")
13
+ end
14
+ else
15
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
16
+ inflect.acronym("GraphiQL")
17
+ end
18
+ end
7
19
 
8
20
  module Decidim
9
21
  module Api
@@ -11,10 +23,6 @@ module Decidim
11
23
  class Engine < ::Rails::Engine
12
24
  isolate_namespace Decidim::Api
13
25
 
14
- initializer "decidim_api.assets" do |app|
15
- app.config.assets.precompile += %w(decidim_api_manifest.js decidim_api_manifest.css)
16
- end
17
-
18
26
  initializer "decidim-api.middleware" do |app|
19
27
  app.config.middleware.insert_before 0, Rack::Cors do
20
28
  allow do
@@ -25,7 +33,7 @@ module Decidim
25
33
  end
26
34
 
27
35
  initializer "decidim-api.graphiql" do
28
- GraphiQL::Rails.config.tap do |config|
36
+ Decidim::GraphiQL::Rails.config.tap do |config|
29
37
  config.query_params = true
30
38
  config.initial_query = File.read(
31
39
  File.join(__dir__, "graphiql-initial-query.txt")
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module GraphiQL
5
+ module Rails
6
+ class Config
7
+ # @example Adding a header to the request
8
+ # config.headers["My-Header"] = -> (view_context) { "My-Value" }
9
+ #
10
+ # @return [Hash<String => Proc>] Keys are headers to include in GraphQL requests, values are `->(view_context) { ... }` procs to determin values
11
+ attr_accessor :headers
12
+
13
+ attr_accessor :query_params, :initial_query, :csrf, :title, :logo
14
+
15
+ DEFAULT_HEADERS = {
16
+ "Content-Type" => ->(_) { "application/json" }
17
+ }.freeze
18
+
19
+ CSRF_TOKEN_HEADER = {
20
+ "X-CSRF-Token" => ->(view_context) { view_context.form_authenticity_token }
21
+ }.freeze
22
+
23
+ # rubocop:disable Metrics/ParameterLists
24
+ def initialize(query_params: false, initial_query: nil, title: nil, logo: nil, csrf: true, headers: DEFAULT_HEADERS)
25
+ @query_params = query_params
26
+ @headers = headers.dup
27
+ @initial_query = initial_query
28
+ @title = title
29
+ @logo = logo
30
+ @csrf = csrf
31
+ end
32
+ # rubocop:enable Metrics/ParameterLists
33
+
34
+ # Call defined procs, add CSRF token if specified
35
+ def resolve_headers(view_context)
36
+ all_headers = DEFAULT_HEADERS.merge(headers)
37
+
38
+ all_headers = all_headers.merge(CSRF_TOKEN_HEADER) if csrf
39
+
40
+ all_headers.transform_values do |value|
41
+ value.call(view_context)
42
+ end
43
+ end
44
+ end
45
+
46
+ class << self
47
+ attr_accessor :config
48
+ end
49
+
50
+ self.config = Config.new
51
+ end
52
+ end
53
+ end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-api version.
5
5
  module Api
6
6
  def self.version
7
- "0.24.0"
7
+ "0.25.0.rc1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.25.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,28 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-03-26 00:00:00.000000000 Z
13
+ date: 2021-07-28 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: graphiql-rails
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: '1.4'
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '1.5'
25
- type: :runtime
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- requirements:
29
- - - "~>"
30
- - !ruby/object:Gem::Version
31
- version: '1.4'
32
- - - "<"
33
- - !ruby/object:Gem::Version
34
- version: '1.5'
35
15
  - !ruby/object:Gem::Dependency
36
16
  name: graphql
37
17
  requirement: !ruby/object:Gem::Requirement
@@ -86,76 +66,62 @@ dependencies:
86
66
  - - ">="
87
67
  - !ruby/object:Gem::Version
88
68
  version: 3.5.1
89
- - !ruby/object:Gem::Dependency
90
- name: sprockets-es6
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: 0.9.2
96
- type: :runtime
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 0.9.2
103
69
  - !ruby/object:Gem::Dependency
104
70
  name: decidim-comments
105
71
  requirement: !ruby/object:Gem::Requirement
106
72
  requirements:
107
73
  - - '='
108
74
  - !ruby/object:Gem::Version
109
- version: 0.24.0
75
+ version: 0.25.0.rc1
110
76
  type: :development
111
77
  prerelease: false
112
78
  version_requirements: !ruby/object:Gem::Requirement
113
79
  requirements:
114
80
  - - '='
115
81
  - !ruby/object:Gem::Version
116
- version: 0.24.0
82
+ version: 0.25.0.rc1
117
83
  - !ruby/object:Gem::Dependency
118
84
  name: decidim-core
119
85
  requirement: !ruby/object:Gem::Requirement
120
86
  requirements:
121
87
  - - '='
122
88
  - !ruby/object:Gem::Version
123
- version: 0.24.0
89
+ version: 0.25.0.rc1
124
90
  type: :development
125
91
  prerelease: false
126
92
  version_requirements: !ruby/object:Gem::Requirement
127
93
  requirements:
128
94
  - - '='
129
95
  - !ruby/object:Gem::Version
130
- version: 0.24.0
96
+ version: 0.25.0.rc1
131
97
  - !ruby/object:Gem::Dependency
132
98
  name: decidim-dev
133
99
  requirement: !ruby/object:Gem::Requirement
134
100
  requirements:
135
101
  - - '='
136
102
  - !ruby/object:Gem::Version
137
- version: 0.24.0
103
+ version: 0.25.0.rc1
138
104
  type: :development
139
105
  prerelease: false
140
106
  version_requirements: !ruby/object:Gem::Requirement
141
107
  requirements:
142
108
  - - '='
143
109
  - !ruby/object:Gem::Version
144
- version: 0.24.0
110
+ version: 0.25.0.rc1
145
111
  - !ruby/object:Gem::Dependency
146
112
  name: decidim-participatory_processes
147
113
  requirement: !ruby/object:Gem::Requirement
148
114
  requirements:
149
115
  - - '='
150
116
  - !ruby/object:Gem::Version
151
- version: 0.24.0
117
+ version: 0.25.0.rc1
152
118
  type: :development
153
119
  prerelease: false
154
120
  version_requirements: !ruby/object:Gem::Requirement
155
121
  requirements:
156
122
  - - '='
157
123
  - !ruby/object:Gem::Version
158
- version: 0.24.0
124
+ version: 0.25.0.rc1
159
125
  description: API engine for decidim
160
126
  email:
161
127
  - josepjaume@gmail.com
@@ -167,22 +133,25 @@ extra_rdoc_files: []
167
133
  files:
168
134
  - README.md
169
135
  - Rakefile
170
- - app/assets/config/decidim_api_manifest.css
171
- - app/assets/config/decidim_api_manifest.js
172
- - app/assets/javascripts/decidim/api/docs.js.es6
173
- - app/assets/stylesheets/decidim/api/docs.scss
174
136
  - app/controllers/decidim/api/application_controller.rb
175
137
  - app/controllers/decidim/api/documentation_controller.rb
176
138
  - app/controllers/decidim/api/graphiql_controller.rb
177
139
  - app/controllers/decidim/api/queries_controller.rb
178
140
  - app/helpers/decidim/api/application_helper.rb
141
+ - app/packs/entrypoints/decidim_api_docs.js
142
+ - app/packs/entrypoints/decidim_api_graphiql.js
143
+ - app/packs/entrypoints/decidim_api_graphiql.scss
144
+ - app/packs/stylesheets/decidim/api/docs.scss
179
145
  - app/views/decidim/api/documentation/show.html.erb
146
+ - app/views/decidim/api/graphiql/show.html.erb
180
147
  - app/views/layouts/decidim/api/documentation.html.erb
148
+ - config/assets.rb
181
149
  - config/routes.rb
182
150
  - docs/usage.md
183
151
  - lib/decidim/api.rb
184
152
  - lib/decidim/api/engine.rb
185
153
  - lib/decidim/api/graphiql-initial-query.txt
154
+ - lib/decidim/api/graphiql/config.rb
186
155
  - lib/decidim/api/mutation_type.rb
187
156
  - lib/decidim/api/query_type.rb
188
157
  - lib/decidim/api/schema.rb
@@ -199,9 +168,6 @@ files:
199
168
  - lib/decidim/api/types/base_scalar.rb
200
169
  - lib/decidim/api/types/base_union.rb
201
170
  - lib/decidim/api/version.rb
202
- - vendor/assets/javascripts/decidim/api/graphql-docs.js
203
- - vendor/assets/javascripts/decidim/api/react-dom.js
204
- - vendor/assets/javascripts/decidim/api/react.js
205
171
  homepage: https://github.com/decidim/decidim
206
172
  licenses:
207
173
  - AGPL-3.0
@@ -217,11 +183,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
183
  version: '2.7'
218
184
  required_rubygems_version: !ruby/object:Gem::Requirement
219
185
  requirements:
220
- - - ">="
186
+ - - ">"
221
187
  - !ruby/object:Gem::Version
222
- version: '0'
188
+ version: 1.3.1
223
189
  requirements: []
224
- rubygems_version: 3.1.2
190
+ rubygems_version: 3.1.4
225
191
  signing_key:
226
192
  specification_version: 4
227
193
  summary: Decidim API module