2018-11-19 20:58:51 +01:00
|
|
|
class Api::V2::Schema < GraphQL::Schema
|
|
|
|
default_max_page_size 100
|
|
|
|
max_complexity 300
|
|
|
|
max_depth 15
|
|
|
|
|
2018-11-19 21:06:13 +01:00
|
|
|
query Types::QueryType
|
|
|
|
mutation Types::MutationType
|
|
|
|
|
2018-11-20 22:59:51 +01:00
|
|
|
def self.id_from_object(object, type_definition, ctx)
|
|
|
|
object.to_typed_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.object_from_id(id, query_ctx)
|
|
|
|
ApplicationRecord.record_from_typed_id(id)
|
|
|
|
rescue => e
|
|
|
|
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.resolve_type(type, obj, ctx)
|
|
|
|
case obj
|
|
|
|
when Procedure
|
|
|
|
Types::DemarcheType
|
|
|
|
when Dossier
|
|
|
|
Types::DossierType
|
2018-11-23 18:54:51 +01:00
|
|
|
when Commentaire
|
|
|
|
Types::MessageType
|
2018-11-20 22:59:51 +01:00
|
|
|
when Instructeur, User
|
|
|
|
Types::ProfileType
|
2019-11-21 18:52:07 +01:00
|
|
|
when Individual
|
|
|
|
Types::PersonnePhysiqueType
|
|
|
|
when Etablissement
|
|
|
|
Types::PersonneMoraleType
|
2020-02-21 11:57:36 +01:00
|
|
|
when GroupeInstructeur
|
|
|
|
Types::GroupeInstructeurType
|
2018-11-20 22:59:51 +01:00
|
|
|
else
|
|
|
|
raise GraphQL::ExecutionError.new("Unexpected object: #{obj}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-28 11:25:41 +02:00
|
|
|
orphan_types Types::Champs::CarteChampType,
|
|
|
|
Types::Champs::CheckboxChampType,
|
2019-11-21 18:52:07 +01:00
|
|
|
Types::Champs::CiviliteChampType,
|
2019-08-28 11:25:41 +02:00
|
|
|
Types::Champs::DateChampType,
|
|
|
|
Types::Champs::DecimalNumberChampType,
|
|
|
|
Types::Champs::DossierLinkChampType,
|
|
|
|
Types::Champs::IntegerNumberChampType,
|
|
|
|
Types::Champs::LinkedDropDownListChampType,
|
|
|
|
Types::Champs::MultipleDropDownListChampType,
|
|
|
|
Types::Champs::PieceJustificativeChampType,
|
|
|
|
Types::Champs::RepetitionChampType,
|
|
|
|
Types::Champs::SiretChampType,
|
|
|
|
Types::Champs::TextChampType,
|
2020-09-24 12:02:14 +02:00
|
|
|
Types::Champs::TitreIdentiteChampType,
|
2019-08-28 11:25:41 +02:00
|
|
|
Types::GeoAreas::ParcelleCadastraleType,
|
2019-11-21 18:52:07 +01:00
|
|
|
Types::GeoAreas::SelectionUtilisateurType,
|
|
|
|
Types::PersonneMoraleType,
|
|
|
|
Types::PersonnePhysiqueType
|
2019-08-28 11:25:41 +02:00
|
|
|
|
2018-11-19 20:58:51 +01:00
|
|
|
def self.unauthorized_object(error)
|
|
|
|
# Add a top-level error to the response instead of returning nil:
|
|
|
|
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })
|
|
|
|
end
|
|
|
|
|
2019-12-05 09:33:48 +01:00
|
|
|
use GraphQL::Execution::Interpreter
|
|
|
|
use GraphQL::Analysis::AST
|
2020-11-05 17:06:44 +01:00
|
|
|
use GraphQL::Schema::Timeout, max_seconds: 10
|
2019-12-05 09:33:48 +01:00
|
|
|
use GraphQL::Batch
|
|
|
|
use GraphQL::Backtrace
|
2018-11-19 20:58:51 +01:00
|
|
|
|
|
|
|
if Rails.env.development?
|
2019-12-05 09:33:48 +01:00
|
|
|
class LogQueryDepth < GraphQL::Analysis::AST::QueryDepth
|
|
|
|
def result
|
|
|
|
Rails.logger.info("[GraphQL Query Depth] #{super}")
|
|
|
|
end
|
|
|
|
end
|
2018-11-19 20:58:51 +01:00
|
|
|
|
2019-12-05 09:33:48 +01:00
|
|
|
class LogQueryComplexity < GraphQL::Analysis::AST::QueryComplexity
|
|
|
|
def result
|
|
|
|
Rails.logger.info("[GraphQL Query Complexity] #{super}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
query_analyzer(LogQueryComplexity)
|
|
|
|
query_analyzer(LogQueryDepth)
|
|
|
|
else
|
|
|
|
query_analyzer(GraphQL::Analysis::AST::MaxQueryComplexity)
|
|
|
|
query_analyzer(GraphQL::Analysis::AST::MaxQueryDepth)
|
|
|
|
end
|
2018-11-19 20:58:51 +01:00
|
|
|
end
|