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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8d6d7b83addc3681b6d1970b669b14ec26d9a239e814b9a097547bfc757b463
4
- data.tar.gz: 2ea6d525732ac2df77f0855a123edf1f2c35aa2ab914f01c3afe88e9150ebcf4
3
+ metadata.gz: 23e1a05e01e205799877dd035e3a1ab5dad7c241f991dcb0a5d52cbe58974d1b
4
+ data.tar.gz: c09028e250e6168da56f3718ecdb3417d8f1b56f97e9c01c89401c234c3cf400
5
5
  SHA512:
6
- metadata.gz: 813e3e16f97fd32d6623c86778c15120531b4ca8e61f9ab5dbd389bb132dbe4a89761922d1059a15944a751b0ad96874f84c44f8ed5d481f7081e34113d3b059
7
- data.tar.gz: 4fc3d29f49a387eac54fb9ed52266ca75ae47d16df50511986c7f5c37faa5e8e3f613063f23020cfe894ddc5fe6eb0628464a8abb25ae6dbcbf8455117ba2b1a
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
- query_string = params[:query]
10
- query_variables = ensure_hash(params[:variables])
11
- result = Schema.execute(query_string, variables: query_variables, context: context)
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 ensure_hash(query_variables)
25
- if query_variables.blank?
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
- query_variables
51
+ raise ArgumentError, "Unexpected parameter: #{variables_param}"
31
52
  end
32
53
  end
33
54
  end
@@ -19,7 +19,7 @@ module Decidim
19
19
  app.config.middleware.insert_before 0, Rack::Cors do
20
20
  allow do
21
21
  origins "*"
22
- resource "*", headers: :any, methods: [:get, :post, :options]
22
+ resource "/api", headers: :any, methods: [:post, :options]
23
23
  end
24
24
  end
25
25
  end
@@ -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 = GraphQL::ObjectType.define do
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,8 +3,7 @@
3
3
  module Decidim
4
4
  module Api
5
5
  # This type represents the root query type of the whole API.
6
- QueryType = GraphQL::ObjectType.define do
7
- name "Query"
6
+ class QueryType < Decidim::Api::Types::BaseObject
8
7
  description "The root query 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 = GraphQL::Schema.define do
7
- query QueryType
8
- mutation MutationType
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 Exception, result["errors"].map { |e| e["message"] }.join(", ") if result["errors"]
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::ObjectType.define do
55
- name "Test#{klass.name}"
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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseArgument < GraphQL::Schema::Argument
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseEnum < GraphQL::Schema::Enum
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseField < GraphQL::Schema::Field
7
+ argument_class Types::BaseArgument
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseInputObject < GraphQL::Schema::InputObject
7
+ argument_class Types::BaseArgument
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ module BaseInterface
7
+ include GraphQL::Schema::Interface
8
+
9
+ field_class Types::BaseField
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseMutation < GraphQL::Schema::RelayClassicMutation
7
+ object_class BaseObject
8
+ field_class BaseField
9
+ input_object_class BaseInputObject
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseObject < GraphQL::Schema::Object
7
+ field_class Types::BaseField
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseScalar < GraphQL::Schema::Scalar
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Api
5
+ module Types
6
+ class BaseUnion < GraphQL::Schema::Union
7
+ end
8
+ end
9
+ end
10
+ end
@@ -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
@@ -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.23.6"
7
+ "0.24.0.rc1"
8
8
  end
9
9
  end
10
10
  end
data/lib/decidim/api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "decidim/api/engine"
4
+ require "decidim/api/types"
4
5
 
5
6
  module Decidim
6
7
  # This module holds all business logic related to exposing a Public API for
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.23.6
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-05-10 00:00:00.000000000 Z
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.9'
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.9'
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.4'
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.4'
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.23.6
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.23.6
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.23.6
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.23.6
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.23.6
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.23.6
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.23.6
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.23.6
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.6'
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: '0'
222
+ version: 1.3.1
200
223
  requirements: []
201
- rubygems_version: 3.0.3
224
+ rubygems_version: 3.1.2
202
225
  signing_key:
203
226
  specification_version: 4
204
227
  summary: Decidim API module