Merge pull request #5532 from tchak/graphql-api-with-revisions

Expose revisions on GraphQL API
This commit is contained in:
Paul Chavard 2020-09-08 11:06:55 +02:00 committed by GitHub
commit 23019ce28a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 19 deletions

View file

@ -304,6 +304,7 @@ type Demarche {
""" """
updatedSince: ISO8601DateTime updatedSince: ISO8601DateTime
): DossierConnection! ): DossierConnection!
draftRevision: Revision!
groupeInstructeurs: [GroupeInstructeur!]! groupeInstructeurs: [GroupeInstructeur!]!
id: ID! id: ID!
@ -311,6 +312,8 @@ type Demarche {
Le numero de la démarche. Le numero de la démarche.
""" """
number: Int! number: Int!
publishedRevision: Revision
revisions: [Revision!]!
service: Service! service: Service!
""" """
@ -411,6 +414,7 @@ type Dossier {
Le numero du dossier. Le numero du dossier.
""" """
number: Int! number: Int!
revision: Revision!
""" """
L'état du dossier. L'état du dossier.
@ -1097,6 +1101,17 @@ type RepetitionChamp implements Champ {
stringValue: String stringValue: String
} }
type Revision {
annotationDescriptors: [ChampDescriptor!]!
champDescriptors: [ChampDescriptor!]!
"""
Date de la création.
"""
dateCreation: ISO8601DateTime!
id: ID!
}
type SelectionUtilisateur implements GeoArea { type SelectionUtilisateur implements GeoArea {
geometry: GeoJSON! geometry: GeoJSON!
id: ID! id: ID!

View file

@ -43,6 +43,10 @@ module Types
field :champ_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ field :champ_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ
field :annotation_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ_private field :annotation_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ_private
field :draft_revision, Types::RevisionType, null: false
field :published_revision, Types::RevisionType, null: true
field :revisions, [Types::RevisionType], null: false
def state def state
object.aasm.current_state object.aasm.current_state
end end
@ -55,6 +59,10 @@ module Types
Loaders::Record.for(Service).load(object.service_id) Loaders::Record.for(Service).load(object.service_id)
end end
def revisions
Loaders::Association.for(object.class, :revisions).load(object)
end
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, order:) def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, order:)
dossiers = object.dossiers.state_not_brouillon.for_api_v2 dossiers = object.dossiers.state_not_brouillon.for_api_v2

View file

@ -24,18 +24,18 @@ module Types
{ Extensions::Attachment => { attachment: :justificatif_motivation } } { Extensions::Attachment => { attachment: :justificatif_motivation } }
] ]
field :usager, Types::ProfileType, null: false
field :groupe_instructeur, Types::GroupeInstructeurType, null: false
field :revision, Types::RevisionType, null: false
field :demandeur, Types::DemandeurType, null: false field :demandeur, Types::DemandeurType, null: false
field :usager, Types::ProfileType, null: false
field :instructeurs, [Types::ProfileType], null: false field :instructeurs, [Types::ProfileType], null: false
field :champs, [Types::ChampType], null: false
field :annotations, [Types::ChampType], null: false
field :messages, [Types::MessageType], null: false field :messages, [Types::MessageType], null: false
field :avis, [Types::AvisType], null: false field :avis, [Types::AvisType], null: false
field :groupe_instructeur, Types::GroupeInstructeurType, null: false field :champs, [Types::ChampType], null: false
field :annotations, [Types::ChampType], null: false
def state def state
object.state object.state
@ -45,14 +45,26 @@ module Types
Loaders::Record.for(User).load(object.user_id) Loaders::Record.for(User).load(object.user_id)
end end
def instructeurs
Loaders::Association.for(object.class, :followers_instructeurs).load(object)
end
def groupe_instructeur def groupe_instructeur
Loaders::Record.for(GroupeInstructeur).load(object.groupe_instructeur_id) Loaders::Record.for(GroupeInstructeur).load(object.groupe_instructeur_id)
end end
def revision
Loaders::Record.for(ProcedureRevision).load(object.revision_id)
end
def demandeur
if object.procedure.for_individual
Loaders::Association.for(object.class, :individual).load(object)
else
Loaders::Association.for(object.class, :etablissement).load(object)
end
end
def instructeurs
Loaders::Association.for(object.class, :followers_instructeurs).load(object)
end
def messages def messages
Loaders::Association.for(object.class, commentaires: [:instructeur, :user]).load(object) Loaders::Association.for(object.class, commentaires: [:instructeur, :user]).load(object)
end end
@ -69,14 +81,6 @@ module Types
Loaders::Association.for(object.class, :champs_private).load(object) Loaders::Association.for(object.class, :champs_private).load(object)
end end
def demandeur
if object.procedure.for_individual
Loaders::Association.for(object.class, :individual).load(object)
else
Loaders::Association.for(object.class, :etablissement).load(object)
end
end
def self.authorized?(object, context) def self.authorized?(object, context)
authorized_demarche?(object.procedure, context) authorized_demarche?(object.procedure, context)
end end

View file

@ -0,0 +1,17 @@
module Types
class RevisionType < Types::BaseObject
global_id_field :id
field :date_creation, GraphQL::Types::ISO8601DateTime, "Date de la création.", null: false, method: :created_at
field :champ_descriptors, [Types::ChampDescriptorType], null: false
field :annotation_descriptors, [Types::ChampDescriptorType], null: false
def champ_descriptors
Loaders::Association.for(object.class, :types_de_champ).load(object)
end
def annotation_descriptors
Loaders::Association.for(object.class, :types_de_champ_private).load(object)
end
end
end

View file

@ -140,7 +140,7 @@ class Procedure < ApplicationRecord
} }
scope :for_api_v2, -> { scope :for_api_v2, -> {
includes(administrateurs: :user) includes(:draft_revision, :published_revision, administrateurs: :user)
} }
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false

View file

@ -63,6 +63,18 @@ describe API::V2::GraphqlController do
email email
} }
} }
revisions {
id
}
draftRevision {
id
}
publishedRevision {
id
champDescriptors {
type
}
}
service { service {
nom nom
typeOrganisme typeOrganisme
@ -123,6 +135,16 @@ describe API::V2::GraphqlController do
label: "défaut" label: "défaut"
} }
], ],
revisions: procedure.revisions.map { |revision| { id: revision.to_typed_id } },
draftRevision: { id: procedure.draft_revision.to_typed_id },
publishedRevision: {
id: procedure.published_revision.to_typed_id,
champDescriptors: procedure.published_types_de_champ.map do |tdc|
{
type: tdc.type_champ
}
end
},
service: { service: {
nom: procedure.service.nom, nom: procedure.service.nom,
typeOrganisme: procedure.service.type_organisme, typeOrganisme: procedure.service.type_organisme,
@ -255,6 +277,12 @@ describe API::V2::GraphqlController do
number number
label label
} }
revision {
id
champDescriptors {
type
}
}
messages { messages {
email email
body body
@ -314,6 +342,14 @@ describe API::V2::GraphqlController do
number: dossier.groupe_instructeur.id, number: dossier.groupe_instructeur.id,
label: dossier.groupe_instructeur.label label: dossier.groupe_instructeur.label
}, },
revision: {
id: dossier.revision.to_typed_id,
champDescriptors: dossier.types_de_champ.map do |tdc|
{
type: tdc.type_champ
}
end
},
demandeur: { demandeur: {
id: dossier.individual.to_typed_id, id: dossier.individual.to_typed_id,
nom: dossier.individual.nom, nom: dossier.individual.nom,