decidim-api 0.23.6 → 0.24.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/decidim/api/queries_controller.rb +29 -8
- data/lib/decidim/api/engine.rb +1 -1
- data/{app/types → lib}/decidim/api/mutation_type.rb +1 -2
- data/{app/types → lib}/decidim/api/query_type.rb +1 -2
- data/{app/types → lib}/decidim/api/schema.rb +3 -5
- data/lib/decidim/api/test/component_context.rb +43 -0
- data/lib/decidim/api/test/type_context.rb +8 -12
- data/lib/decidim/api/types/base_argument.rb +10 -0
- data/lib/decidim/api/types/base_enum.rb +10 -0
- data/lib/decidim/api/types/base_field.rb +11 -0
- data/lib/decidim/api/types/base_input_object.rb +11 -0
- data/lib/decidim/api/types/base_interface.rb +13 -0
- data/lib/decidim/api/types/base_mutation.rb +13 -0
- data/lib/decidim/api/types/base_object.rb +11 -0
- data/lib/decidim/api/types/base_scalar.rb +10 -0
- data/lib/decidim/api/types/base_union.rb +10 -0
- data/lib/decidim/api/types.rb +21 -0
- data/lib/decidim/api/version.rb +1 -1
- data/lib/decidim/api.rb +1 -0
- metadata +44 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23e1a05e01e205799877dd035e3a1ab5dad7c241f991dcb0a5d52cbe58974d1b
|
4
|
+
data.tar.gz: c09028e250e6168da56f3718ecdb3417d8f1b56f97e9c01c89401c234c3cf400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2cfd1193fbdaecfbf9aca96afee9abbcb90bd2c6a9733bbb5586e7187736e2ece83ba2107e1d4746bb12a8c812b8df0cc13fb45dee979a55ce2b75c1dd127f
|
7
|
+
data.tar.gz: 386717784c7361c751b09eac778583de5dda11e8b27f666744f63ed716d3904473368cd8fb992b96fc5cc0127debe76d1da4daad581084502f2dba4970b54116
|
@@ -6,10 +6,22 @@ module Decidim
|
|
6
6
|
# the Schema to be executed, later returning the response as JSON.
|
7
7
|
class QueriesController < Api::ApplicationController
|
8
8
|
def create
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
variables = prepare_variables(params[:variables])
|
10
|
+
query = params[:query]
|
11
|
+
operation_name = params[:operationName]
|
12
|
+
result = Schema.execute(query, variables: variables, context: context, operation_name: operation_name)
|
12
13
|
render json: result
|
14
|
+
rescue StandardError => e
|
15
|
+
logger.error e.message
|
16
|
+
logger.error e.backtrace.join("\n")
|
17
|
+
|
18
|
+
message = if Rails.env.development?
|
19
|
+
{ message: e.message, backtrace: e.backtrace }
|
20
|
+
else
|
21
|
+
{ message: "Internal Server error" }
|
22
|
+
end
|
23
|
+
|
24
|
+
render json: { errors: [message], data: {} }, status: :internal_server_error
|
13
25
|
end
|
14
26
|
|
15
27
|
private
|
@@ -21,13 +33,22 @@ module Decidim
|
|
21
33
|
}
|
22
34
|
end
|
23
35
|
|
24
|
-
def
|
25
|
-
|
36
|
+
def prepare_variables(variables_param)
|
37
|
+
case variables_param
|
38
|
+
when String
|
39
|
+
if variables_param.present?
|
40
|
+
JSON.parse(variables_param) || {}
|
41
|
+
else
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
when Hash
|
45
|
+
variables_param
|
46
|
+
when ActionController::Parameters
|
47
|
+
variables_param.to_unsafe_hash # GraphQL-Ruby will validate name and type of incoming variables.
|
48
|
+
when nil
|
26
49
|
{}
|
27
|
-
elsif query_variables.is_a?(String)
|
28
|
-
JSON.parse(query_variables)
|
29
50
|
else
|
30
|
-
|
51
|
+
raise ArgumentError, "Unexpected parameter: #{variables_param}"
|
31
52
|
end
|
32
53
|
end
|
33
54
|
end
|
data/lib/decidim/api/engine.rb
CHANGED
@@ -3,8 +3,7 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Api
|
5
5
|
# This type represents the root mutation type of the whole API
|
6
|
-
MutationType
|
7
|
-
name "Mutation"
|
6
|
+
class MutationType < Decidim::Api::Types::BaseObject
|
8
7
|
description "The root mutation of this schema"
|
9
8
|
end
|
10
9
|
end
|
@@ -3,17 +3,15 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Api
|
5
5
|
# Main GraphQL schema for decidim's API.
|
6
|
-
Schema
|
7
|
-
|
8
|
-
|
6
|
+
class Schema < GraphQL::Schema
|
7
|
+
mutation(MutationType)
|
8
|
+
query(QueryType)
|
9
9
|
|
10
10
|
default_max_page_size 50
|
11
11
|
max_depth 15
|
12
12
|
max_complexity 300
|
13
13
|
|
14
14
|
orphan_types(Api.orphan_types)
|
15
|
-
|
16
|
-
resolve_type ->(_type, _obj, _ctx) {}
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/api/test/type_context"
|
4
|
+
|
5
|
+
shared_context "with a graphql decidim component" do
|
6
|
+
include_context "with a graphql class type"
|
7
|
+
|
8
|
+
let(:schema) { Decidim::Api::Schema }
|
9
|
+
|
10
|
+
let(:locale) { "en" }
|
11
|
+
|
12
|
+
let(:participatory_process) { create :participatory_process, organization: current_organization }
|
13
|
+
let(:category) { create(:category, participatory_space: participatory_process) }
|
14
|
+
|
15
|
+
let(:component_type) {}
|
16
|
+
let(:component_fragment) {}
|
17
|
+
|
18
|
+
let(:participatory_process_query) do
|
19
|
+
%(
|
20
|
+
participatoryProcess(id: #{participatory_process.id}) {
|
21
|
+
components(filter: {type: "#{component_type}"}){
|
22
|
+
id
|
23
|
+
name {
|
24
|
+
translation(locale: "#{locale}")
|
25
|
+
}
|
26
|
+
weight
|
27
|
+
__typename
|
28
|
+
...fooComponent
|
29
|
+
}
|
30
|
+
id
|
31
|
+
}
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:query) do
|
36
|
+
%(
|
37
|
+
query {
|
38
|
+
#{participatory_process_query}
|
39
|
+
}
|
40
|
+
#{component_fragment}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
shared_context "with a graphql type" do
|
3
|
+
shared_context "with a graphql class type" do
|
4
4
|
let!(:current_organization) { create(:organization) }
|
5
5
|
let!(:current_user) { create(:user, organization: current_organization) }
|
6
6
|
let(:model) { OpenStruct.new({}) }
|
@@ -10,13 +10,9 @@ shared_context "with a graphql type" do
|
|
10
10
|
|
11
11
|
let(:schema) do
|
12
12
|
klass = type_class
|
13
|
-
|
14
|
-
GraphQL::Schema.define do
|
13
|
+
Class.new(Decidim::Api::Schema) do
|
15
14
|
query klass
|
16
|
-
|
17
15
|
orphan_types(Decidim::Api.orphan_types)
|
18
|
-
|
19
|
-
resolve_type ->(_type, _obj, _ctx) {}
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
@@ -35,14 +31,14 @@ shared_context "with a graphql type" do
|
|
35
31
|
variables: variables
|
36
32
|
)
|
37
33
|
|
38
|
-
raise
|
34
|
+
raise StandardError, result["errors"].map { |e| e["message"] }.join(", ") if result["errors"]
|
39
35
|
|
40
36
|
result["data"]
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
shared_context "with a graphql scalar type" do
|
45
|
-
include_context "with a graphql type"
|
40
|
+
shared_context "with a graphql scalar class type" do
|
41
|
+
include_context "with a graphql class type"
|
46
42
|
|
47
43
|
let(:root_value) do
|
48
44
|
OpenStruct.new(value: model)
|
@@ -51,11 +47,11 @@ shared_context "with a graphql scalar type" do
|
|
51
47
|
let(:type_class) do
|
52
48
|
klass = described_class
|
53
49
|
|
54
|
-
GraphQL::
|
55
|
-
|
50
|
+
Class.new(GraphQL::Schema::Object) do
|
51
|
+
graphql_name "ScalarFieldType"
|
56
52
|
description "Fake test type"
|
57
53
|
|
58
|
-
field :value, klass
|
54
|
+
field :value, klass, null: false
|
59
55
|
end
|
60
56
|
end
|
61
57
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Api
|
5
|
+
autoload :QueryType, "decidim/api/query_type"
|
6
|
+
autoload :MutationType, "decidim/api/mutation_type"
|
7
|
+
autoload :Schema, "decidim/api/schema"
|
8
|
+
|
9
|
+
module Types
|
10
|
+
autoload :BaseArgument, "decidim/api/types/base_argument"
|
11
|
+
autoload :BaseEnum, "decidim/api/types/base_enum"
|
12
|
+
autoload :BaseField, "decidim/api/types/base_field"
|
13
|
+
autoload :BaseInputObject, "decidim/api/types/base_input_object"
|
14
|
+
autoload :BaseInterface, "decidim/api/types/base_interface"
|
15
|
+
autoload :BaseMutation, "decidim/api/types/base_mutation"
|
16
|
+
autoload :BaseObject, "decidim/api/types/base_object"
|
17
|
+
autoload :BaseScalar, "decidim/api/types/base_scalar"
|
18
|
+
autoload :BaseUnion, "decidim/api/types/base_union"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/decidim/api/version.rb
CHANGED
data/lib/decidim/api.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.24.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep Jaume Rey Peroy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: graphiql-rails
|
@@ -38,14 +38,20 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.12'
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.12.3
|
42
45
|
type: :runtime
|
43
46
|
prerelease: false
|
44
47
|
version_requirements: !ruby/object:Gem::Requirement
|
45
48
|
requirements:
|
46
49
|
- - "~>"
|
47
50
|
- !ruby/object:Gem::Version
|
48
|
-
version: '1.
|
51
|
+
version: '1.12'
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.12.3
|
49
55
|
- !ruby/object:Gem::Dependency
|
50
56
|
name: rack-cors
|
51
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,14 +72,20 @@ dependencies:
|
|
66
72
|
requirements:
|
67
73
|
- - "~>"
|
68
74
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
75
|
+
version: '3.5'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.5.1
|
70
79
|
type: :runtime
|
71
80
|
prerelease: false
|
72
81
|
version_requirements: !ruby/object:Gem::Requirement
|
73
82
|
requirements:
|
74
83
|
- - "~>"
|
75
84
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
85
|
+
version: '3.5'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.5.1
|
77
89
|
- !ruby/object:Gem::Dependency
|
78
90
|
name: sprockets-es6
|
79
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,56 +106,56 @@ dependencies:
|
|
94
106
|
requirements:
|
95
107
|
- - '='
|
96
108
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
109
|
+
version: 0.24.0.rc1
|
98
110
|
type: :development
|
99
111
|
prerelease: false
|
100
112
|
version_requirements: !ruby/object:Gem::Requirement
|
101
113
|
requirements:
|
102
114
|
- - '='
|
103
115
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
116
|
+
version: 0.24.0.rc1
|
105
117
|
- !ruby/object:Gem::Dependency
|
106
118
|
name: decidim-core
|
107
119
|
requirement: !ruby/object:Gem::Requirement
|
108
120
|
requirements:
|
109
121
|
- - '='
|
110
122
|
- !ruby/object:Gem::Version
|
111
|
-
version: 0.
|
123
|
+
version: 0.24.0.rc1
|
112
124
|
type: :development
|
113
125
|
prerelease: false
|
114
126
|
version_requirements: !ruby/object:Gem::Requirement
|
115
127
|
requirements:
|
116
128
|
- - '='
|
117
129
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.
|
130
|
+
version: 0.24.0.rc1
|
119
131
|
- !ruby/object:Gem::Dependency
|
120
132
|
name: decidim-dev
|
121
133
|
requirement: !ruby/object:Gem::Requirement
|
122
134
|
requirements:
|
123
135
|
- - '='
|
124
136
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.
|
137
|
+
version: 0.24.0.rc1
|
126
138
|
type: :development
|
127
139
|
prerelease: false
|
128
140
|
version_requirements: !ruby/object:Gem::Requirement
|
129
141
|
requirements:
|
130
142
|
- - '='
|
131
143
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.
|
144
|
+
version: 0.24.0.rc1
|
133
145
|
- !ruby/object:Gem::Dependency
|
134
146
|
name: decidim-participatory_processes
|
135
147
|
requirement: !ruby/object:Gem::Requirement
|
136
148
|
requirements:
|
137
149
|
- - '='
|
138
150
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.
|
151
|
+
version: 0.24.0.rc1
|
140
152
|
type: :development
|
141
153
|
prerelease: false
|
142
154
|
version_requirements: !ruby/object:Gem::Requirement
|
143
155
|
requirements:
|
144
156
|
- - '='
|
145
157
|
- !ruby/object:Gem::Version
|
146
|
-
version: 0.
|
158
|
+
version: 0.24.0.rc1
|
147
159
|
description: API engine for decidim
|
148
160
|
email:
|
149
161
|
- josepjaume@gmail.com
|
@@ -164,9 +176,6 @@ files:
|
|
164
176
|
- app/controllers/decidim/api/graphiql_controller.rb
|
165
177
|
- app/controllers/decidim/api/queries_controller.rb
|
166
178
|
- app/helpers/decidim/api/application_helper.rb
|
167
|
-
- app/types/decidim/api/mutation_type.rb
|
168
|
-
- app/types/decidim/api/query_type.rb
|
169
|
-
- app/types/decidim/api/schema.rb
|
170
179
|
- app/views/decidim/api/documentation/show.html.erb
|
171
180
|
- app/views/layouts/decidim/api/documentation.html.erb
|
172
181
|
- config/routes.rb
|
@@ -174,7 +183,21 @@ files:
|
|
174
183
|
- lib/decidim/api.rb
|
175
184
|
- lib/decidim/api/engine.rb
|
176
185
|
- lib/decidim/api/graphiql-initial-query.txt
|
186
|
+
- lib/decidim/api/mutation_type.rb
|
187
|
+
- lib/decidim/api/query_type.rb
|
188
|
+
- lib/decidim/api/schema.rb
|
189
|
+
- lib/decidim/api/test/component_context.rb
|
177
190
|
- lib/decidim/api/test/type_context.rb
|
191
|
+
- lib/decidim/api/types.rb
|
192
|
+
- lib/decidim/api/types/base_argument.rb
|
193
|
+
- lib/decidim/api/types/base_enum.rb
|
194
|
+
- lib/decidim/api/types/base_field.rb
|
195
|
+
- lib/decidim/api/types/base_input_object.rb
|
196
|
+
- lib/decidim/api/types/base_interface.rb
|
197
|
+
- lib/decidim/api/types/base_mutation.rb
|
198
|
+
- lib/decidim/api/types/base_object.rb
|
199
|
+
- lib/decidim/api/types/base_scalar.rb
|
200
|
+
- lib/decidim/api/types/base_union.rb
|
178
201
|
- lib/decidim/api/version.rb
|
179
202
|
- vendor/assets/javascripts/decidim/api/graphql-docs.js
|
180
203
|
- vendor/assets/javascripts/decidim/api/react-dom.js
|
@@ -191,14 +214,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
214
|
requirements:
|
192
215
|
- - ">="
|
193
216
|
- !ruby/object:Gem::Version
|
194
|
-
version: '2.
|
217
|
+
version: '2.7'
|
195
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
219
|
requirements:
|
197
|
-
- - "
|
220
|
+
- - ">"
|
198
221
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
222
|
+
version: 1.3.1
|
200
223
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
224
|
+
rubygems_version: 3.1.2
|
202
225
|
signing_key:
|
203
226
|
specification_version: 4
|
204
227
|
summary: Decidim API module
|