decidim-api 0.24.2 → 0.25.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/decidim/api/graphiql_controller.rb +6 -3
- data/app/{assets/javascripts/decidim/api/docs.js.es6 → packs/entrypoints/decidim_api_docs.js} +7 -6
- data/app/packs/entrypoints/decidim_api_graphiql.js +90 -0
- data/app/packs/entrypoints/decidim_api_graphiql.scss +10 -0
- data/app/{assets → packs}/stylesheets/decidim/api/docs.scss +0 -0
- data/app/views/decidim/api/graphiql/show.html.erb +24 -0
- data/app/views/layouts/decidim/api/documentation.html.erb +2 -2
- data/config/assets.rb +9 -0
- data/lib/decidim/api/engine.rb +15 -7
- data/lib/decidim/api/graphiql/config.rb +53 -0
- data/lib/decidim/api/version.rb +1 -1
- metadata +19 -53
- data/app/assets/config/decidim_api_manifest.css +0 -3
- data/app/assets/config/decidim_api_manifest.js +0 -1
- data/vendor/assets/javascripts/decidim/api/graphql-docs.js +0 -7851
- data/vendor/assets/javascripts/decidim/api/react-dom.js +0 -42
- data/vendor/assets/javascripts/decidim/api/react.js +0 -20595
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 582b1b755a9bac496dadc3b753a203d5c3b7a1db8a16e96e3ea26e900e70f4b6
|
4
|
+
data.tar.gz: cdb7fb1fb5eee2af5c6467155c7ab5a272b7be3a9d8309a40504414f5e92ca6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ab41eb83c85bdc76e435a1273ecc788bd8c0b950f97207a954c7ac096060402d22951ae144df2f54e22bc59add53a56894315466e5a27134419ca062d425e63
|
7
|
+
data.tar.gz: d09b4ebf1c16634c35468763f7ee3a02be45976a6685776525aa5240b7c8ea84308a5c0dcdfad7219d22da4691fb25cf3e77d91cb9e5ac82a0f4a0cb726afa72
|
@@ -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 < ::
|
7
|
+
class GraphiQLController < Api::ApplicationController
|
8
8
|
include NeedsOrganization
|
9
9
|
include ForceAuthentication
|
10
10
|
|
11
|
-
def
|
12
|
-
|
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
|
data/app/{assets/javascripts/decidim/api/docs.js.es6 → packs/entrypoints/decidim_api_docs.js}
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
/* eslint-disable react/jsx-no-undef */
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
22
|
-
<GraphQLDocs
|
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
|
+
});
|
File without changes
|
@@ -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", defer: false) %>
|
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
|
-
<%=
|
5
|
-
<%=
|
4
|
+
<%= javascript_pack_tag "decidim_api_docs", defer: false %>
|
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
|
+
)
|
data/lib/decidim/api/engine.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/decidim/api/version.rb
CHANGED
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.
|
4
|
+
version: 0.25.0.rc3
|
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-
|
13
|
+
date: 2021-09-17 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.
|
75
|
+
version: 0.25.0.rc3
|
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.
|
82
|
+
version: 0.25.0.rc3
|
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.
|
89
|
+
version: 0.25.0.rc3
|
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.
|
96
|
+
version: 0.25.0.rc3
|
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.
|
103
|
+
version: 0.25.0.rc3
|
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.
|
110
|
+
version: 0.25.0.rc3
|
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.
|
117
|
+
version: 0.25.0.rc3
|
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.
|
124
|
+
version: 0.25.0.rc3
|
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,9 +183,9 @@ 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:
|
188
|
+
version: 1.3.1
|
223
189
|
requirements: []
|
224
190
|
rubygems_version: 3.1.2
|
225
191
|
signing_key:
|