This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The server now knows how to return `SDUIComponent` union including filter of supported components via `supported` arg. adeira-source-id: 27a09043f0e6688560cf239d4e61c7b629ab6d83
- Loading branch information
1 parent
a14d2fa
commit 487ba26
Showing
22 changed files
with
202 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"database":"_system","lastTickAtDumpStart":"90475","properties":{"id":"1","name":"_system","isSystem":true}} | ||
{"database":"_system","lastTickAtDumpStart":"132102","properties":{"id":"1","name":"_system","isSystem":true}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"database":"ya-comiste","lastTickAtDumpStart":"90477","properties":{"id":"84144","name":"ya-comiste","isSystem":false}} | ||
{"database":"ya-comiste","lastTickAtDumpStart":"132104","properties":{"id":"84144","name":"ya-comiste","isSystem":false}} |
2 changes: 1 addition & 1 deletion
2
rust/arangodb/dump/ya-comiste/entrypoint_sections_6c1f9f90c0181a0fe73698084cda2c0b.data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
{"type":2300,"data":{"_key":"89538","_id":"entrypoint_sections/89538","_from":"entrypoints/com.yaComiste.Explore","_to":"sections/10771","_rev":"_bff4636---"}} | ||
{"type":2300,"data":{"_key":"89458","_id":"entrypoint_sections/89458","_from":"entrypoints/com.yaComiste.Explore","_to":"sections/9810","_rev":"_bfgGf26---","user":"users/87047"}} | ||
{"type":2300,"data":{"_key":"89458","_id":"entrypoint_sections/89458","_from":"entrypoints/com.yaComiste.Explore","_to":"sections/9810","_rev":"_bgJE1wa---"}} |
4 changes: 2 additions & 2 deletions
4
rust/arangodb/dump/ya-comiste/sections_ff4dee88db82e98f0e0d524d965b9aa7.data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
{"type":2300,"data":{"_key":"9810","_id":"sections/9810","_rev":"_bff1zcW---","section_order":1,"title":"Places nearby","type":"SDUIScrollViewHorizontalComponent"}} | ||
{"type":2300,"data":{"_key":"10771","_id":"sections/10771","_rev":"_bff2ICi---","section_order":2,"title":"Bakeries nearby","type":"SDUIScrollViewHorizontalComponent"}} | ||
{"type":2300,"data":{"_key":"9810","_id":"sections/9810","_rev":"_bgLK4YO---","order":1,"component":{"typename":"SDUIScrollViewHorizontalComponent"}}} | ||
{"type":2300,"data":{"_key":"10771","_id":"sections/10771","_rev":"_bgLL-8W---","order":2,"component":{"typename":"SDUIScrollViewHorizontalComponent"}}} |
2 changes: 1 addition & 1 deletion
2
rust/arangodb/dump/ya-comiste/sections_ff4dee88db82e98f0e0d524d965b9aa7.structure.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"indexes":[],"parameters":{"allowUserKeys":true,"cacheEnabled":false,"cid":"85191","deleted":false,"globallyUniqueId":"hC8B4EB76885F/9751","id":"85191","isDisjoint":false,"isSmart":false,"isSmartChild":false,"isSystem":false,"keyOptions":{"allowUserKeys":true,"type":"traditional","lastValue":11596},"minReplicationFactor":1,"name":"sections","numberOfShards":1,"planId":"9751","replicationFactor":1,"schema":{"message":"","level":"strict","rule":{"type":"object","oneOf":[{"properties":{"section_order":{"type":"number"},"type":{"const":"SDUIScrollViewHorizontalComponent"},"title":{"type":"string"}},"additionalProperties":false,"required":["section_order","type","title"]},{"properties":{"section_order":{"type":"number"},"type":{"const":"SDUICardComponent"}},"additionalProperties":false,"required":["section_order","type"]}]}},"shardKeys":["_key"],"shards":{},"status":3,"tempObjectId":"0","type":2,"version":9,"waitForSync":false,"writeConcern":1}} | ||
{"indexes":[],"parameters":{"allowUserKeys":true,"cacheEnabled":false,"cid":"85191","deleted":false,"globallyUniqueId":"hC8B4EB76885F/9751","id":"85191","isDisjoint":false,"isSmart":false,"isSmartChild":false,"isSystem":false,"keyOptions":{"allowUserKeys":true,"type":"traditional","lastValue":11596},"minReplicationFactor":1,"name":"sections","numberOfShards":1,"planId":"9751","replicationFactor":1,"schema":null,"shardKeys":["_key"],"shards":{},"status":3,"tempObjectId":"0","type":2,"version":9,"waitForSync":false,"writeConcern":1}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
use graphql::graphql_context::Context; | ||
|
||
/// TODO: maybe `MobileEntrypoint` would be a better name so we are future proof? | ||
#[derive(Clone, Debug, serde::Deserialize)] | ||
pub struct Entrypoint { | ||
pub _id: juniper::ID, | ||
pub _id: String, | ||
pub _key: String, | ||
} | ||
|
||
#[juniper::graphql_object(context = Context)] | ||
impl Entrypoint { | ||
fn id(&self) -> &str { | ||
&self._id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod entrypoints; | ||
pub mod sdui_sections; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::errors::ModelError; | ||
use crate::model::entrypoints::get_entrypoint; | ||
use crate::sdui_component::SDUIComponent; | ||
use crate::sdui_section::SDUISection; | ||
use arangodb::connection; | ||
|
||
/// Note: this function doesn't return `section.component` on purpose. | ||
pub async fn get_all_sections_for_entrypoint_key( | ||
entrypoint_key: String, | ||
) -> Result<Vec<SDUISection>, ModelError> { | ||
let conn = connection().await; | ||
let db = conn.db("ya-comiste").await.unwrap(); | ||
|
||
let entrypoint = get_entrypoint(&entrypoint_key).await?; | ||
let aql = arangors::AqlQuery::builder() | ||
.query( | ||
" | ||
FOR section IN 1..1 OUTBOUND @entrypoint_id entrypoint_sections | ||
LET component = section.component | ||
SORT section.order ASC | ||
RETURN { | ||
id: section._id, | ||
} | ||
", | ||
) | ||
.bind_var("entrypoint_id", entrypoint._id.to_string()) | ||
.batch_size(1) | ||
.build(); | ||
|
||
match db.aql_query::<SDUISection>(aql).await { | ||
Ok(r) => Ok(r), | ||
Err(e) => Err(ModelError::DatabaseError(e)), | ||
} | ||
} | ||
|
||
pub async fn get_section_component( | ||
section_id: String, | ||
supported: Vec<String>, | ||
) -> Result<SDUIComponent, ModelError> { | ||
let conn = connection().await; | ||
let db = conn.db("ya-comiste").await.unwrap(); | ||
|
||
// TODO: change the component ID to be unique (how to 🤔) | ||
let aql = arangors::AqlQuery::builder() | ||
.query( | ||
" | ||
LET section = DOCUMENT(@section_id) | ||
LET component = section.component | ||
FILTER component.typename IN @supported_typenames | ||
LIMIT 1 | ||
RETURN { | ||
typename: component.typename, | ||
id: CONCAT(section._id, '~', component.typename), | ||
} | ||
", | ||
) | ||
.bind_var("section_id", section_id) | ||
.bind_var("supported_typenames", supported) | ||
.batch_size(1) | ||
.build(); | ||
|
||
match db.aql_query::<SDUIComponent>(aql).await { | ||
Ok(r) => match r.first() { | ||
Some(first) => Ok(first.to_owned()), | ||
None => Err(ModelError::LogicError( | ||
"no supported component available".to_string(), | ||
)), | ||
}, | ||
Err(e) => Err(ModelError::DatabaseError(e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use graphql::graphql_context::Context; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize)] | ||
pub struct SDUICardComponent { | ||
pub id: String, | ||
} | ||
|
||
#[juniper::graphql_object(context = Context)] | ||
impl SDUICardComponent { | ||
fn id(&self) -> juniper::ID { | ||
juniper::ID::new(&self.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::sdui_card_component::SDUICardComponent; | ||
use crate::sdui_description_component::SDUIDescriptionComponent; | ||
use crate::sdui_jumbotron_component::SDUIJumbotronComponent; | ||
use crate::sdui_scrollview_horizontal_component::SDUIScrollViewHorizontalComponent; | ||
use graphql::graphql_context::Context; | ||
use juniper::GraphQLUnion; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize, GraphQLUnion)] | ||
#[graphql(Context = Context)] | ||
#[serde(tag = "typename")] | ||
pub enum SDUIComponent { | ||
SDUICardComponent(SDUICardComponent), | ||
SDUIDescriptionComponent(SDUIDescriptionComponent), | ||
SDUIJumbotronComponent(SDUIJumbotronComponent), | ||
SDUIScrollViewHorizontalComponent(SDUIScrollViewHorizontalComponent), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use graphql::graphql_context::Context; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize)] | ||
pub struct SDUIDescriptionComponent { | ||
pub id: String, | ||
} | ||
|
||
#[juniper::graphql_object(context = Context)] | ||
impl SDUIDescriptionComponent { | ||
fn id(&self) -> juniper::ID { | ||
juniper::ID::new(&self.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use graphql::graphql_context::Context; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize)] | ||
pub struct SDUIJumbotronComponent { | ||
pub id: String, | ||
} | ||
|
||
#[juniper::graphql_object(context = Context)] | ||
impl SDUIJumbotronComponent { | ||
fn id(&self) -> juniper::ID { | ||
juniper::ID::new(&self.id) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
rust/crates/sdui/src/sdui_scrollview_horizontal_component.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use graphql::graphql_context::Context; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize)] | ||
pub struct SDUIScrollViewHorizontalComponent { | ||
pub id: String, | ||
} | ||
|
||
#[juniper::graphql_object(context = Context)] | ||
impl SDUIScrollViewHorizontalComponent { | ||
fn id(&self) -> juniper::ID { | ||
juniper::ID::new(&self.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters