fix(graphql): properly handle demarche and demarche_descriptor resolution
This commit is contained in:
parent
e1594a2814
commit
3f2a91b855
1 changed files with 12 additions and 6 deletions
|
@ -12,23 +12,29 @@ class API::V2::Schema < GraphQL::Schema
|
||||||
context_class API::V2::Context
|
context_class API::V2::Context
|
||||||
|
|
||||||
def self.id_from_object(object, type_definition, ctx)
|
def self.id_from_object(object, type_definition, ctx)
|
||||||
if object.is_a?(Hash)
|
if type_definition == Types::DemarcheDescriptorType
|
||||||
|
(object.is_a?(Procedure) ? object : object.procedure).to_typed_id
|
||||||
|
elsif object.is_a?(Hash)
|
||||||
object[:id]
|
object[:id]
|
||||||
else
|
else
|
||||||
object.to_typed_id
|
object.to_typed_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.object_from_id(id, query_ctx)
|
def self.object_from_id(id, ctx)
|
||||||
ApplicationRecord.record_from_typed_id(id)
|
ApplicationRecord.record_from_typed_id(id)
|
||||||
rescue => e
|
rescue => e
|
||||||
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
|
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.resolve_type(type, obj, ctx)
|
def self.resolve_type(type_definition, object, ctx)
|
||||||
case obj
|
case object
|
||||||
when Procedure
|
when Procedure
|
||||||
Types::DemarcheType
|
if type_definition == Types::DemarcheDescriptorType
|
||||||
|
type_definition
|
||||||
|
else
|
||||||
|
Types::DemarcheType
|
||||||
|
end
|
||||||
when Dossier
|
when Dossier
|
||||||
Types::DossierType
|
Types::DossierType
|
||||||
when Commentaire
|
when Commentaire
|
||||||
|
@ -42,7 +48,7 @@ class API::V2::Schema < GraphQL::Schema
|
||||||
when GroupeInstructeur
|
when GroupeInstructeur
|
||||||
Types::GroupeInstructeurType
|
Types::GroupeInstructeurType
|
||||||
else
|
else
|
||||||
raise GraphQL::ExecutionError.new("Unexpected object: #{obj}")
|
raise GraphQL::ExecutionError.new("Unexpected object: #{object}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue