decidim-api 0.30.8 → 0.31.0.rc1
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/application_controller.rb +20 -0
- data/app/controllers/decidim/api/queries_controller.rb +33 -2
- data/app/controllers/decidim/api/sessions_controller.rb +61 -0
- data/app/models/decidim/api/api_user.rb +82 -0
- data/app/models/decidim/api/jwt_denylist.rb +11 -0
- data/app/packs/entrypoints/decidim_api_graphiql.js +2 -1
- data/app/presenters/decidim/api/api_user_presenter.rb +23 -0
- data/config/assets.rb +2 -2
- data/config/initializers/devise.rb +26 -0
- data/config/routes.rb +8 -0
- data/decidim-api.gemspec +2 -1
- data/docs/usage.md +98 -8
- data/lib/decidim/api/component_mutation_type.rb +19 -0
- data/lib/decidim/api/devise.rb +12 -0
- data/lib/decidim/api/engine.rb +2 -2
- data/lib/decidim/api/graphql_permissions.rb +125 -0
- data/lib/decidim/api/mutation_type.rb +10 -0
- data/lib/decidim/api/required_scopes.rb +31 -0
- data/lib/decidim/api/schema.rb +0 -6
- data/lib/decidim/api/test/component_context.rb +17 -19
- data/lib/decidim/api/test/factories.rb +33 -0
- data/lib/decidim/api/test/mutation_context.rb +38 -0
- data/lib/decidim/api/test/shared_examples/amendable_interface_examples.rb +14 -0
- data/lib/decidim/api/test/shared_examples/amendable_proposals_interface_examples.rb +50 -0
- data/lib/decidim/api/test/shared_examples/attachable_interface_examples.rb +40 -0
- data/lib/decidim/api/test/shared_examples/authorable_interface_examples.rb +46 -0
- data/lib/decidim/api/test/shared_examples/categories_container_examples.rb +22 -0
- data/lib/decidim/api/test/shared_examples/categorizable_interface_examples.rb +27 -0
- data/lib/decidim/api/test/shared_examples/coauthorable_interface_examples.rb +77 -0
- data/lib/decidim/api/test/shared_examples/commentable_interface_examples.rb +13 -0
- data/lib/decidim/api/test/shared_examples/fingerprintable_interface_examples.rb +17 -0
- data/lib/decidim/api/test/shared_examples/followable_interface_examples.rb +13 -0
- data/lib/decidim/api/test/shared_examples/input_filter_examples.rb +77 -0
- data/lib/decidim/api/test/shared_examples/input_sort_examples.rb +126 -0
- data/lib/decidim/api/test/shared_examples/likeable_interface_examples.rb +22 -0
- data/lib/decidim/api/test/shared_examples/localizable_interface_examples.rb +29 -0
- data/lib/decidim/api/test/shared_examples/participatory_space_resourcable_interface_examples.rb +61 -0
- data/lib/decidim/api/test/shared_examples/referable_interface_examples.rb +13 -0
- data/lib/decidim/api/test/shared_examples/scopable_interface_examples.rb +19 -0
- data/lib/decidim/api/test/shared_examples/statistics_examples.rb +30 -16
- data/lib/decidim/api/test/shared_examples/taxonomizable_interface_examples.rb +20 -0
- data/lib/decidim/api/test/shared_examples/timestamps_interface_examples.rb +21 -0
- data/lib/decidim/api/test/shared_examples/traceable_interface_examples.rb +49 -0
- data/lib/decidim/api/test/type_context.rb +9 -92
- data/lib/decidim/api/test.rb +21 -0
- data/lib/decidim/api/types/base_mutation.rb +5 -1
- data/lib/decidim/api/types/base_object.rb +4 -69
- data/lib/decidim/api/types.rb +3 -9
- data/lib/decidim/api/version.rb +1 -1
- data/lib/decidim/api.rb +23 -15
- data/lib/devise/models/api_authenticatable.rb +30 -0
- data/lib/devise/strategies/api_authenticatable.rb +21 -0
- data/lib/warden/jwt_auth/decidim_overrides.rb +42 -0
- metadata +66 -84
- data/config/locales/am-ET.yml +0 -1
- data/config/locales/ar.yml +0 -1
- data/config/locales/bg.yml +0 -1
- data/config/locales/bn-BD.yml +0 -1
- data/config/locales/bs-BA.yml +0 -1
- data/config/locales/ca-IT.yml +0 -8
- data/config/locales/ca.yml +0 -8
- data/config/locales/cs.yml +0 -7
- data/config/locales/da.yml +0 -1
- data/config/locales/de.yml +0 -1
- data/config/locales/el.yml +0 -1
- data/config/locales/en.yml +0 -8
- data/config/locales/eo.yml +0 -1
- data/config/locales/es-MX.yml +0 -8
- data/config/locales/es-PY.yml +0 -8
- data/config/locales/es.yml +0 -8
- data/config/locales/et.yml +0 -1
- data/config/locales/eu.yml +0 -8
- data/config/locales/fa-IR.yml +0 -1
- data/config/locales/fi-plain.yml +0 -8
- data/config/locales/fi.yml +0 -8
- data/config/locales/fr-CA.yml +0 -8
- data/config/locales/fr.yml +0 -8
- data/config/locales/ga-IE.yml +0 -1
- data/config/locales/gl.yml +0 -1
- data/config/locales/gn-PY.yml +0 -1
- data/config/locales/he-IL.yml +0 -1
- data/config/locales/hr.yml +0 -1
- data/config/locales/hu.yml +0 -1
- data/config/locales/id-ID.yml +0 -1
- data/config/locales/is-IS.yml +0 -1
- data/config/locales/it.yml +0 -1
- data/config/locales/ja.yml +0 -8
- data/config/locales/ka-GE.yml +0 -1
- data/config/locales/kaa.yml +0 -1
- data/config/locales/ko.yml +0 -1
- data/config/locales/lb.yml +0 -1
- data/config/locales/lo-LA.yml +0 -1
- data/config/locales/lt.yml +0 -1
- data/config/locales/lv.yml +0 -1
- data/config/locales/mt.yml +0 -1
- data/config/locales/nl.yml +0 -1
- data/config/locales/no.yml +0 -6
- data/config/locales/oc-FR.yml +0 -1
- data/config/locales/om-ET.yml +0 -1
- data/config/locales/pl.yml +0 -1
- data/config/locales/pt-BR.yml +0 -8
- data/config/locales/pt.yml +0 -1
- data/config/locales/ro-RO.yml +0 -8
- data/config/locales/ru.yml +0 -1
- data/config/locales/si-LK.yml +0 -1
- data/config/locales/sk.yml +0 -1
- data/config/locales/sl.yml +0 -1
- data/config/locales/so-SO.yml +0 -1
- data/config/locales/sq-AL.yml +0 -1
- data/config/locales/sr-CS.yml +0 -1
- data/config/locales/sv.yml +0 -8
- data/config/locales/sw-KE.yml +0 -1
- data/config/locales/th-TH.yml +0 -1
- data/config/locales/ti-ER.yml +0 -1
- data/config/locales/tr-TR.yml +0 -1
- data/config/locales/uk.yml +0 -1
- data/config/locales/val-ES.yml +0 -1
- data/config/locales/vi.yml +0 -1
- data/config/locales/zh-CN.yml +0 -1
- data/config/locales/zh-TW.yml +0 -1
- data/lib/decidim/api/alias_analyzer.rb +0 -23
- data/lib/decidim/api/decidim_introspection.rb +0 -51
- data/lib/decidim/api/errors/introspection_disabled_error.rb +0 -14
- data/lib/decidim/api/errors/recursion_limit_exceeded_error.rb +0 -14
- data/lib/decidim/api/errors/too_many_aliases_error.rb +0 -15
- data/lib/decidim/api/recursion_analyzer.rb +0 -74
data/config/locales/es-MX.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
es-MX:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: La introspección está desactivada para esta solicitud
|
|
7
|
-
recursion_limit_exceeded_error: Se han detectado demasiadas consultas recurrentes
|
|
8
|
-
too_many_aliases_error: Has utilizado demasiados alias (nicknames). Has usado %{size} alias, pero se permite un máximo de %{limit}.
|
data/config/locales/es-PY.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
es-PY:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: La introspección está desactivada para esta solicitud
|
|
7
|
-
recursion_limit_exceeded_error: Se han detectado demasiadas consultas recurrentes
|
|
8
|
-
too_many_aliases_error: Has utilizado demasiados alias (nicknames). Has usado %{size} alias, pero se permite un máximo de %{limit}.
|
data/config/locales/es.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
es:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: La introspección está desactivada para esta solicitud
|
|
7
|
-
recursion_limit_exceeded_error: Se han detectado demasiadas consultas recurrentes
|
|
8
|
-
too_many_aliases_error: Has utilizado demasiados alias (nicknames). Has usado %{size} alias, pero se permite un máximo de %{limit}.
|
data/config/locales/et.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
et:
|
data/config/locales/eu.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
eu:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: Eskaera honetarako introspekzioa ezgaitu egin da
|
|
7
|
-
recursion_limit_exceeded_error: Kontsultan atzemandako errekurtso gehiegi
|
|
8
|
-
too_many_aliases_error: Ezizen gehiegi erabiltzen dira. %{size} ezizen erabili dituzu, baina %{limit} onartuta daude.
|
data/config/locales/fa-IR.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
fa:
|
data/config/locales/fi-plain.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
fi-pl:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: Rajapintamallin tarkastelu ei ole käytössä tälle pyynnölle
|
|
7
|
-
recursion_limit_exceeded_error: Rajapintakyselyssä on liikaa rekursiivisia kyselyitä
|
|
8
|
-
too_many_aliases_error: Rajapintakysely käyttää liian monta alias-nimitystä. Kyselyssä on %{size} aliasta, mutta maksimissaan %{limit} on sallittu.
|
data/config/locales/fi.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
fi:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: Rajapintamallin tarkastelu ei ole käytössä tälle pyynnölle
|
|
7
|
-
recursion_limit_exceeded_error: Rajapintakyselyssä on liikaa rekursiivisia kyselyitä
|
|
8
|
-
too_many_aliases_error: Rajapintakysely käyttää liian monta alias-nimitystä. Kyselyssä on %{size} aliasta, mutta maksimissaan %{limit} on sallittu.
|
data/config/locales/fr-CA.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
fr-CA:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: L'introspection est désactivée pour cette requête
|
|
7
|
-
recursion_limit_exceeded_error: Trop de récursions détectées dans la requête
|
|
8
|
-
too_many_aliases_error: Trop d'alias utilisés. Vous avez utilisé %{size} alias, mais seulement %{limit} sont autorisés.
|
data/config/locales/fr.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
fr:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: L'introspection est désactivée pour cette requête
|
|
7
|
-
recursion_limit_exceeded_error: Trop de récursions détectées dans la requête
|
|
8
|
-
too_many_aliases_error: Trop d'alias utilisés. Vous avez utilisé %{size} alias, mais seulement %{limit} sont autorisés.
|
data/config/locales/ga-IE.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ga:
|
data/config/locales/gl.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
gl:
|
data/config/locales/gn-PY.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
gn:
|
data/config/locales/he-IL.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
he:
|
data/config/locales/hr.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
hr:
|
data/config/locales/hu.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
hu:
|
data/config/locales/id-ID.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
id:
|
data/config/locales/is-IS.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
is-IS:
|
data/config/locales/it.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
it:
|
data/config/locales/ja.yml
DELETED
data/config/locales/ka-GE.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ka:
|
data/config/locales/kaa.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
kaa:
|
data/config/locales/ko.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ko:
|
data/config/locales/lb.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
lb:
|
data/config/locales/lo-LA.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
lo:
|
data/config/locales/lt.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
lt:
|
data/config/locales/lv.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
lv:
|
data/config/locales/mt.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
mt:
|
data/config/locales/nl.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nl:
|
data/config/locales/no.yml
DELETED
data/config/locales/oc-FR.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
oc:
|
data/config/locales/om-ET.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
om:
|
data/config/locales/pl.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pl:
|
data/config/locales/pt-BR.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
pt-BR:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: A inspeção está desabilitada para esta requisição
|
|
7
|
-
recursion_limit_exceeded_error: Muitas recursões detectadas na consulta
|
|
8
|
-
too_many_aliases_error: Foram utilizados muitos codinomes. Você usou %{size} codinomes, mas são permitidos apenas %{limit}.
|
data/config/locales/pt.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pt:
|
data/config/locales/ro-RO.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
ro:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: Introspection este dezactivat pentru această solicitare
|
|
7
|
-
recursion_limit_exceeded_error: Prea multe recursiuni detectate în interogare
|
|
8
|
-
too_many_aliases_error: Prea multe aliasuri folosite. Ați folosit aliasuri %{size}, dar %{limit} sunt permise.
|
data/config/locales/ru.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ru:
|
data/config/locales/si-LK.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
si:
|
data/config/locales/sk.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sk:
|
data/config/locales/sl.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sl:
|
data/config/locales/so-SO.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
so:
|
data/config/locales/sq-AL.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sq:
|
data/config/locales/sr-CS.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sr:
|
data/config/locales/sv.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sv:
|
|
3
|
-
decidim:
|
|
4
|
-
api:
|
|
5
|
-
errors:
|
|
6
|
-
introspection_disabled: Introspektion är inaktiverad för denna begäran
|
|
7
|
-
recursion_limit_exceeded_error: Alltför många rekursioner upptäckta i frågan
|
|
8
|
-
too_many_aliases_error: För många alias som används. Du har använt %{size} alias, men %{limit} är tillåtna.
|
data/config/locales/sw-KE.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sw:
|
data/config/locales/th-TH.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
th:
|
data/config/locales/ti-ER.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ti:
|
data/config/locales/tr-TR.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
tr:
|
data/config/locales/uk.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uk:
|
data/config/locales/val-ES.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
val:
|
data/config/locales/vi.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
vi:
|
data/config/locales/zh-CN.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
zh-CN:
|
data/config/locales/zh-TW.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
zh-TW:
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Api
|
|
5
|
-
class AliasAnalyzer < GraphQL::Analysis::AST::Analyzer
|
|
6
|
-
def initialize(query)
|
|
7
|
-
super
|
|
8
|
-
|
|
9
|
-
@aliases = Set.new
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def on_enter_field(node, _parent, _visitor)
|
|
13
|
-
@aliases.add(node.alias) if node.alias.present?
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def result
|
|
17
|
-
if @aliases.size > Decidim::Api.max_aliases
|
|
18
|
-
Errors::TooManyAliasesError.new(I18n.t("decidim.api.errors.too_many_aliases_error", size: @aliases.size, limit: Decidim::Api.max_aliases))
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Api
|
|
5
|
-
module DecidimIntrospection
|
|
6
|
-
module FieldVisibility
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
included do
|
|
10
|
-
def self.visible?(context)
|
|
11
|
-
raise Errors::IntrospectionDisabledError, I18n.t("decidim.api.errors.introspection_disabled") unless context[:can_introspect] == true
|
|
12
|
-
|
|
13
|
-
super
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class SchemaType < GraphQL::Introspection::SchemaType
|
|
19
|
-
include FieldVisibility
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class TypeType < GraphQL::Introspection::TypeType
|
|
23
|
-
include FieldVisibility
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class DirectiveType < GraphQL::Introspection::DirectiveType
|
|
27
|
-
include FieldVisibility
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class DirectiveLocationEnum < GraphQL::Introspection::DirectiveLocationEnum
|
|
31
|
-
include FieldVisibility
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
class EnumValueType < GraphQL::Introspection::EnumValueType
|
|
35
|
-
include FieldVisibility
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class FieldType < GraphQL::Introspection::FieldType
|
|
39
|
-
include FieldVisibility
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
class InputValueType < GraphQL::Introspection::InputValueType
|
|
43
|
-
include FieldVisibility
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class TypeKindEnum < GraphQL::Introspection::TypeKindEnum
|
|
47
|
-
include FieldVisibility
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Api
|
|
5
|
-
module Errors
|
|
6
|
-
# i18n-tasks-use t("decidim.api.errors.introspection_disabled")
|
|
7
|
-
class IntrospectionDisabledError < GraphQL::ExecutionError
|
|
8
|
-
def to_h
|
|
9
|
-
super.merge({ "extensions" => { "code" => "INTROSPECTION_DISABLED_ERROR" } })
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Api
|
|
5
|
-
module Errors
|
|
6
|
-
# i18n-tasks-use t("decidim.api.errors.recursion_limit_exceeded_error")
|
|
7
|
-
class RecursionLimitExceededError < GraphQL::AnalysisError
|
|
8
|
-
def to_h
|
|
9
|
-
super.merge({ "extensions" => { "code" => "RECURSION_LIMIT_EXCEEDED_ERROR" } })
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Api
|
|
5
|
-
module Errors
|
|
6
|
-
# i18n-tasks-use t("decidim.api.errors.too_many_aliases_error")
|
|
7
|
-
|
|
8
|
-
class TooManyAliasesError < GraphQL::AnalysisError
|
|
9
|
-
def to_h
|
|
10
|
-
super.merge({ "extensions" => { "code" => "TOO_MANY_ALIASES_ERROR" } })
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# This analyzer checks for too many recursions in GraphQL queries.
|
|
4
|
-
# Copyright (c) GitLab B.V.
|
|
5
|
-
# License: MIT Expat license
|
|
6
|
-
# This content of the class was copied from the GitLab repository
|
|
7
|
-
# @see https://gitlab.com/gitlab-org/gitlab/-/blob/f59f7aa0d86f07496e68abf7172edd703669e7bd/lib/gitlab/graphql/query_analyzers/ast/recursion_analyzer.rb
|
|
8
|
-
# To which I have modified the result format to be compatible with decidim-api.
|
|
9
|
-
|
|
10
|
-
module Decidim
|
|
11
|
-
module Api
|
|
12
|
-
class RecursionAnalyzer < GraphQL::Analysis::AST::Analyzer
|
|
13
|
-
IGNORED_FIELDS = %w(node edges nodes ofType).freeze
|
|
14
|
-
RECURSION_THRESHOLD = 2
|
|
15
|
-
|
|
16
|
-
def initialize(query)
|
|
17
|
-
super
|
|
18
|
-
|
|
19
|
-
@node_visits = {}
|
|
20
|
-
@recurring_fields = {}
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def on_enter_field(node, _parent, visitor)
|
|
24
|
-
return if skip_node?(node, visitor)
|
|
25
|
-
|
|
26
|
-
node_name = node.name
|
|
27
|
-
node_visits[node_name] ||= 0
|
|
28
|
-
node_visits[node_name] += 1
|
|
29
|
-
|
|
30
|
-
times_encountered = @node_visits[node_name]
|
|
31
|
-
recurring_fields[node_name] = times_encountered if recursion_too_deep?(node_name, times_encountered)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Visitors are all defined on the AST::Analyzer base class
|
|
35
|
-
# We override them for custom analyzers.
|
|
36
|
-
def on_leave_field(node, _parent, visitor)
|
|
37
|
-
return if skip_node?(node, visitor)
|
|
38
|
-
|
|
39
|
-
node_name = node.name
|
|
40
|
-
node_visits[node_name] ||= 0
|
|
41
|
-
node_visits[node_name] -= 1
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def result
|
|
45
|
-
@recurring_fields = @recurring_fields.select { |k, v| recursion_too_deep?(k, v) }
|
|
46
|
-
|
|
47
|
-
Decidim::Api::Errors::RecursionLimitExceededError.new I18n.t("decidim.api.errors.recursion_limit_exceeded_error") if @recurring_fields.any?
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
attr_reader :node_visits, :recurring_fields
|
|
53
|
-
|
|
54
|
-
def recursion_too_deep?(node_name, times_encountered)
|
|
55
|
-
return false if IGNORED_FIELDS.include?(node_name)
|
|
56
|
-
|
|
57
|
-
times_encountered > recursion_threshold
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def skip_node?(node, visitor)
|
|
61
|
-
# We do not want to count skipped fields or fields
|
|
62
|
-
# inside fragment definitions
|
|
63
|
-
return false if visitor.skipping? || visitor.visiting_fragment_definition?
|
|
64
|
-
|
|
65
|
-
!node.is_a?(GraphQL::Language::Nodes::Field) || node.selections.empty?
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Separated into a method to allow overriding or customization of the recursion limit.
|
|
69
|
-
def recursion_threshold
|
|
70
|
-
RECURSION_THRESHOLD
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|