[GraphQL] expose file information
This commit is contained in:
parent
1146447c14
commit
422b7f37ec
9 changed files with 59 additions and 19 deletions
|
@ -28,9 +28,9 @@ module Extensions
|
||||||
# This method is called if the result of the `resolve`
|
# This method is called if the result of the `resolve`
|
||||||
# is a lazy value (e.g., a Promise – like in our case)
|
# is a lazy value (e.g., a Promise – like in our case)
|
||||||
def after_resolve(value:, **_rest)
|
def after_resolve(value:, **_rest)
|
||||||
return if value.nil?
|
if value&.virus_scanner&.safe? || value&.virus_scanner&.pending?
|
||||||
|
value
|
||||||
Rails.application.routes.url_helpers.url_for(value)
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ type Association {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Avis {
|
type Avis {
|
||||||
attachmentUrl: URL
|
attachment: File
|
||||||
dateQuestion: ISO8601DateTime!
|
dateQuestion: ISO8601DateTime!
|
||||||
dateReponse: ISO8601DateTime
|
dateReponse: ISO8601DateTime
|
||||||
expert: Profile
|
expert: Profile
|
||||||
|
@ -383,7 +383,7 @@ type Dossier {
|
||||||
instructeurs: [Profile!]!
|
instructeurs: [Profile!]!
|
||||||
messages: [Message!]!
|
messages: [Message!]!
|
||||||
motivation: String
|
motivation: String
|
||||||
motivationAttachmentUrl: URL
|
motivationAttachment: File
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Le numero du dossier.
|
Le numero du dossier.
|
||||||
|
@ -663,6 +663,14 @@ type Entreprise {
|
||||||
siretSiegeSocial: String!
|
siretSiegeSocial: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type File {
|
||||||
|
byteSize: Int!
|
||||||
|
checksum: String!
|
||||||
|
contentType: String!
|
||||||
|
filename: String!
|
||||||
|
url: URL!
|
||||||
|
}
|
||||||
|
|
||||||
interface GeoArea {
|
interface GeoArea {
|
||||||
geometry: GeoJSON!
|
geometry: GeoJSON!
|
||||||
id: ID!
|
id: ID!
|
||||||
|
@ -742,7 +750,7 @@ type LinkedDropDownListChamp implements Champ {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message {
|
type Message {
|
||||||
attachmentUrl: URL
|
attachment: File
|
||||||
body: String!
|
body: String!
|
||||||
createdAt: ISO8601DateTime!
|
createdAt: ISO8601DateTime!
|
||||||
email: String!
|
email: String!
|
||||||
|
@ -875,6 +883,7 @@ type PersonnePhysique implements Demandeur {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PieceJustificativeChamp implements Champ {
|
type PieceJustificativeChamp implements Champ {
|
||||||
|
file: File
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -886,7 +895,6 @@ type PieceJustificativeChamp implements Champ {
|
||||||
La valeur du champ sous forme texte.
|
La valeur du champ sous forme texte.
|
||||||
"""
|
"""
|
||||||
stringValue: String
|
stringValue: String
|
||||||
url: URL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Profile {
|
type Profile {
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Types
|
||||||
field :date_question, GraphQL::Types::ISO8601DateTime, null: false, method: :created_at
|
field :date_question, GraphQL::Types::ISO8601DateTime, null: false, method: :created_at
|
||||||
field :date_reponse, GraphQL::Types::ISO8601DateTime, null: true, method: :updated_at
|
field :date_reponse, GraphQL::Types::ISO8601DateTime, null: true, method: :updated_at
|
||||||
|
|
||||||
field :attachment_url, Types::URL, null: true, extensions: [
|
field :attachment, Types::File, null: true, extensions: [
|
||||||
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
|
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Types::Champs
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
implements Types::ChampType
|
implements Types::ChampType
|
||||||
|
|
||||||
field :url, Types::URL, null: true, extensions: [
|
field :file, Types::File, null: true, extensions: [
|
||||||
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
|
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Types
|
||||||
field :archived, Boolean, null: false
|
field :archived, Boolean, null: false
|
||||||
|
|
||||||
field :motivation, String, null: true
|
field :motivation, String, null: true
|
||||||
field :motivation_attachment_url, Types::URL, null: true, extensions: [
|
field :motivation_attachment, Types::File, null: true, extensions: [
|
||||||
{ Extensions::Attachment => { attachment: :justificatif_motivation } }
|
{ Extensions::Attachment => { attachment: :justificatif_motivation } }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
13
app/graphql/types/file.rb
Normal file
13
app/graphql/types/file.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module Types
|
||||||
|
class File < Types::BaseObject
|
||||||
|
field :url, Types::URL, null: false
|
||||||
|
field :filename, String, null: false
|
||||||
|
field :byte_size, Int, null: false
|
||||||
|
field :checksum, String, null: false
|
||||||
|
field :content_type, String, null: false
|
||||||
|
|
||||||
|
def url
|
||||||
|
Rails.application.routes.url_helpers.url_for(object)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,7 +4,7 @@ module Types
|
||||||
field :email, String, null: false
|
field :email, String, null: false
|
||||||
field :body, String, null: false
|
field :body, String, null: false
|
||||||
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
|
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
|
||||||
field :attachment_url, Types::URL, null: true, extensions: [
|
field :attachment, Types::File, null: true, extensions: [
|
||||||
{ Extensions::Attachment => { attachment: :piece_jointe } }
|
{ Extensions::Attachment => { attachment: :piece_jointe } }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
DEFAULT_QUERY = "# La documentation officielle de la spécification (Anglais) : https://graphql.org/
|
DEFAULT_QUERY = "# La documentation officielle de la spécification (Anglais) : https://graphql.org/
|
||||||
# Une introduction aux concepts et raisons d'être de GraphQL (Français) : https://blog.octo.com/graphql-et-pourquoi-faire/
|
# Une introduction aux concepts et raisons d'être de GraphQL (Français) : https://blog.octo.com/graphql-et-pourquoi-faire/
|
||||||
# Le schema GraphQL de demarches-simplifiees.fr : https://demarches-simplifiees-graphql.netlify.com
|
# Le schema GraphQL de demarches-simplifiees.fr : https://demarches-simplifiees-graphql.netlify.com
|
||||||
# Le endpoint GraphQL de demarches-simplifiees.fr : https://demarches-simplifiees.fr/api/v2/graphql
|
# Le endpoint GraphQL de demarches-simplifiees.fr : https://www.demarches-simplifiees.fr/api/v2/graphql
|
||||||
|
|
||||||
query getDemarche($demarcheNumber: Int!) {
|
query getDemarche($demarcheNumber: Int!) {
|
||||||
demarche(number: $demarcheNumber) {
|
demarche(number: $demarcheNumber) {
|
||||||
|
@ -54,7 +54,9 @@ query getDemarche($demarcheNumber: Int!) {
|
||||||
secondaryValue
|
secondaryValue
|
||||||
}
|
}
|
||||||
... on PieceJustificativeChamp {
|
... on PieceJustificativeChamp {
|
||||||
url
|
file {
|
||||||
|
url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
... on CarteChamp {
|
... on CarteChamp {
|
||||||
geoAreas {
|
geoAreas {
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe API::V2::GraphqlController do
|
||||||
:with_all_champs,
|
:with_all_champs,
|
||||||
:for_individual,
|
:for_individual,
|
||||||
procedure: procedure)
|
procedure: procedure)
|
||||||
create(:commentaire, dossier: dossier, email: 'test@test.com')
|
create(:commentaire, :with_file, dossier: dossier, email: 'test@test.com')
|
||||||
dossier
|
dossier
|
||||||
end
|
end
|
||||||
let(:dossier1) { create(:dossier, :en_construction, :for_individual, procedure: procedure, en_construction_at: 1.day.ago) }
|
let(:dossier1) { create(:dossier, :en_construction, :for_individual, procedure: procedure, en_construction_at: 1.day.ago) }
|
||||||
|
@ -155,7 +155,9 @@ describe API::V2::GraphqlController do
|
||||||
datePassageEnInstruction
|
datePassageEnInstruction
|
||||||
dateTraitement
|
dateTraitement
|
||||||
motivation
|
motivation
|
||||||
motivationAttachmentUrl
|
motivationAttachment {
|
||||||
|
url
|
||||||
|
}
|
||||||
usager {
|
usager {
|
||||||
id
|
id
|
||||||
email
|
email
|
||||||
|
@ -176,7 +178,13 @@ describe API::V2::GraphqlController do
|
||||||
messages {
|
messages {
|
||||||
email
|
email
|
||||||
body
|
body
|
||||||
attachmentUrl
|
attachment {
|
||||||
|
filename
|
||||||
|
checksum
|
||||||
|
byteSize
|
||||||
|
contentType
|
||||||
|
url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
avis {
|
avis {
|
||||||
expert {
|
expert {
|
||||||
|
@ -186,7 +194,10 @@ describe API::V2::GraphqlController do
|
||||||
reponse
|
reponse
|
||||||
dateQuestion
|
dateQuestion
|
||||||
dateReponse
|
dateReponse
|
||||||
attachmentUrl
|
attachment {
|
||||||
|
url
|
||||||
|
filename
|
||||||
|
}
|
||||||
}
|
}
|
||||||
champs {
|
champs {
|
||||||
id
|
id
|
||||||
|
@ -209,7 +220,7 @@ describe API::V2::GraphqlController do
|
||||||
datePassageEnInstruction: nil,
|
datePassageEnInstruction: nil,
|
||||||
dateTraitement: nil,
|
dateTraitement: nil,
|
||||||
motivation: nil,
|
motivation: nil,
|
||||||
motivationAttachmentUrl: nil,
|
motivationAttachment: nil,
|
||||||
usager: {
|
usager: {
|
||||||
id: dossier.user.to_typed_id,
|
id: dossier.user.to_typed_id,
|
||||||
email: dossier.user.email
|
email: dossier.user.email
|
||||||
|
@ -230,7 +241,13 @@ describe API::V2::GraphqlController do
|
||||||
messages: dossier.commentaires.map do |commentaire|
|
messages: dossier.commentaires.map do |commentaire|
|
||||||
{
|
{
|
||||||
body: commentaire.body,
|
body: commentaire.body,
|
||||||
attachmentUrl: nil,
|
attachment: {
|
||||||
|
filename: commentaire.piece_jointe.filename.to_s,
|
||||||
|
contentType: commentaire.piece_jointe.content_type,
|
||||||
|
checksum: commentaire.piece_jointe.checksum,
|
||||||
|
byteSize: commentaire.piece_jointe.byte_size,
|
||||||
|
url: Rails.application.routes.url_helpers.url_for(commentaire.piece_jointe)
|
||||||
|
},
|
||||||
email: commentaire.email
|
email: commentaire.email
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in a new issue