Commit 56ea5740 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Flatten tree of documents before sending it with GraphQL.

parent 44dc25fd
Pipeline #100067 passed with stage
in 2 minutes and 17 seconds
......@@ -1057,9 +1057,16 @@ graphql_object!(DeclarationGouvernement: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field type_declaration() -> &Codier {
......@@ -1110,9 +1117,16 @@ graphql_object!(DepotAccordInternational: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1159,9 +1173,16 @@ graphql_object!(DepotAvisConseilEtat: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1208,9 +1229,16 @@ graphql_object!(DepotInitiative: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1237,12 +1265,6 @@ pub struct DepotInitiativeNavette {
pub uid: String,
}
// impl DepotInitiativeNavette {
// fn texte_associe<'a>(&self, context: &'a Context) -> Option<&'a Document> {
// context.get_document_at_uid(&self.texte_associe)
// }
// }
graphql_object!(DepotInitiativeNavette: Context |&self| {
field code_acte() -> &str {
&self.code_acte
......@@ -1268,9 +1290,16 @@ graphql_object!(DepotInitiativeNavette: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1329,9 +1358,16 @@ graphql_object!(DepotLettreRectificative: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1481,9 +1517,16 @@ graphql_object!(DepotRapport: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -1716,9 +1759,16 @@ graphql_object!(EtudeImpact: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......@@ -2155,9 +2205,16 @@ graphql_object!(RetraitInitiative: Context |&self| {
&self.texte_associe
}
field texte_associe(&executor) -> Option<&Document> {
field texte_associe(&executor) -> Vec<&Document> {
let context = &executor.context();
context.get_document_at_uid(&self.texte_associe)
match context.get_document_at_uid(&self.texte_associe) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
}
field uid() -> &str {
......
......@@ -808,12 +808,19 @@ graphql_object!(TexteLeg: Context |&self| {
}
}
field texte_legislatif(&executor) -> Option<&Document> {
field texte_legislatif(&executor) -> Vec<&Document> {
match &self.ref_texte_legislatif {
None => None,
None => vec![],
Some(ref ref_texte_legislatif) => {
let context = &executor.context();
context.get_document_at_uid(ref_texte_legislatif)
match context.get_document_at_uid(ref_texte_legislatif) {
None => vec![],
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
document.flatten_document()
},
}
},
}
}
......
......@@ -241,6 +241,11 @@ pub fn load(
}
for mut wrapper in &mut dossiers_legislatifs_wrappers {
for mut document in &mut wrapper.export.textes_legislatifs.documents {
let mut index: i32 = 0;
document.index_document(&mut index);
}
for mut dossier in &mut wrapper.export.dossiers_legislatifs.dossiers {
dossier.dossier_parlementaire.index_actes_legislatifs();
}
......
This diff is collapsed.
......@@ -339,14 +339,22 @@ graphql_object!(Query: Context |&self| {
Ok(deputes)
}
field document(&executor, uid: String) -> FieldResult<Option<&Document>> {
Ok(executor.context().get_document_at_uid(&uid))
field document(&executor, uid: String) -> FieldResult<Vec<&Document>> {
match executor.context().get_document_at_uid(&uid) {
None => Ok(vec![]),
Some(ref document) => {
// Generate a flat vector from document and its sub-documents (aka divisions),
// because a tree is not adapted to GraphQL.
Ok(document.flatten_document())
},
}
}
field documents(&executor) -> FieldResult<Vec<&Document>> {
let mut documents: Vec<&Document> = Vec::new();
for wrapper in &executor.context().dossiers_legislatifs_wrappers {
for document in &wrapper.export.textes_legislatifs.documents {
// TODO: Document should be flatten?
documents.push(&document);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment