Skip to content

Commit 441554b

Browse files
author
RobJellinghaus
committed
SupplierList mostly works??? Will test after hanging with dad
1 parent cbf89f0 commit 441554b

9 files changed

Lines changed: 923 additions & 60 deletions

File tree

.cargo/bin/dsync.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn main() {
2121
options: GenerationConfigOpts {
2222
default_table_options: TableOptions::default()
2323
.tsync()
24-
.graphql()
2524
.autogenerated_columns(vec![
2625
"id",
2726
"created_at",
@@ -42,6 +41,10 @@ pub fn main() {
4241
("user_oauth2_links", TableOptions::default().ignore()),
4342
// plugin_tasks
4443
("fang_tasks", TableOptions::default().ignore()),
44+
// enable GraphQL only for todo table
45+
("todo", TableOptions::default().tsync().graphql()),
46+
// suppliers - disable GraphQL generation due to template issues
47+
("suppliers", TableOptions::default().tsync()),
4548
]),
4649
..Default::default()
4750
},

backend/graphql/query.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use async_graphql::{Context, Object, Result};
22
use create_rust_app::auth::Auth;
33
use create_rust_app::Database;
44
use crate::models::todo::{Todo, TodoFilter, PaginationResult as TodoPaginationResult, ConnectionType};
5-
use crate::models::suppliers::{Suppliers, SuppliersFilter, PaginationResult as SupplierPaginationResult};
5+
use crate::models::suppliers::{Suppliers, SuppliersFilter, SupplierPaginationResult};
66

77
fn get_connection(ctx: &Context<'_>) -> Result<ConnectionType> {
88
let db = ctx.data::<Database>()?;
@@ -38,13 +38,14 @@ impl QueryRoot {
3838
.map_err(|e| async_graphql::Error::new(format!("Database error: {}", e)))
3939
}
4040

41-
async fn suppliers(&self, ctx: &Context<'_>, page: Option<i64>, page_size: Option<i64>) -> Result<SupplierPaginationResult<Suppliers>> {
41+
async fn suppliers(&self, ctx: &Context<'_>, page: Option<i64>, page_size: Option<i64>) -> Result<SupplierPaginationResult> {
4242
let mut con = get_connection(ctx)?;
4343

4444
let page = page.unwrap_or(0);
4545
let page_size = page_size.unwrap_or(10);
4646

4747
Suppliers::paginate(&mut con, page, page_size, SuppliersFilter::default())
48+
.map(|result| result.into())
4849
.map_err(|e| async_graphql::Error::new(format!("Database error: {}", e)))
4950
}
5051

backend/models/suppliers/generated.rs

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -39,61 +39,6 @@ pub struct Suppliers {
3939
pub updated_at: chrono::DateTime<chrono::Utc>,
4040
}
4141

42-
#[async_graphql::Object]
43-
impl Suppliers {
44-
async fn id(&self) -> async_graphql::ID {
45-
async_graphql::ID(self.id.to_string())
46-
}
47-
48-
async fn name(&self) -> &String {
49-
&self.name
50-
}
51-
52-
async fn address(&self) -> &String {
53-
&self.address
54-
}
55-
56-
async fn city(&self) -> &String {
57-
&self.city
58-
}
59-
60-
async fn state(&self) -> &String {
61-
&self.state
62-
}
63-
64-
async fn zip_code(&self) -> &String {
65-
&self.zip_code
66-
}
67-
68-
async fn country(&self) -> &String {
69-
&self.country
70-
}
71-
72-
async fn contact_name(&self) -> &String {
73-
&self.contact_name
74-
}
75-
76-
async fn contact_email(&self) -> &String {
77-
&self.contact_email
78-
}
79-
80-
async fn contact_phone(&self) -> &String {
81-
&self.contact_phone
82-
}
83-
84-
async fn website(&self) -> &Option<String> {
85-
&self.website
86-
}
87-
88-
async fn created_at(&self) -> &chrono::DateTime<chrono::Utc> {
89-
&self.created_at
90-
}
91-
92-
async fn updated_at(&self) -> &chrono::DateTime<chrono::Utc> {
93-
&self.updated_at
94-
}
95-
}
96-
9742
/// Create Struct for a row in table `suppliers` for [`Suppliers`]
9843
#[tsync::tsync]
9944
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)]
@@ -154,8 +99,8 @@ pub struct UpdateSuppliers {
15499

155100
/// Result of a `.paginate` function
156101
#[tsync::tsync]
157-
#[derive(Debug, serde::Serialize, async_graphql::SimpleObject)]
158-
pub struct PaginationResult<T: Send + Sync + async_graphql::OutputType> {
102+
#[derive(Debug, serde::Serialize)]
103+
pub struct PaginationResult<T> {
159104
/// Resulting items that are from the current page
160105
pub items: Vec<T>,
161106
/// The count of total items there are
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use async_graphql::{SimpleObject, Object};
2+
use super::generated::{Suppliers, PaginationResult};
3+
4+
// Manual GraphQL Object implementation for Suppliers
5+
// This is needed because dsync's hardcoded GraphQL template assumes a "text" field
6+
// which doesn't exist in the suppliers table
7+
#[Object]
8+
impl Suppliers {
9+
async fn id(&self) -> async_graphql::ID {
10+
async_graphql::ID(self.id.to_string())
11+
}
12+
13+
async fn name(&self) -> &String {
14+
&self.name
15+
}
16+
17+
async fn address(&self) -> &String {
18+
&self.address
19+
}
20+
21+
async fn city(&self) -> &String {
22+
&self.city
23+
}
24+
25+
async fn state(&self) -> &String {
26+
&self.state
27+
}
28+
29+
async fn zip_code(&self) -> &String {
30+
&self.zip_code
31+
}
32+
33+
async fn country(&self) -> &String {
34+
&self.country
35+
}
36+
37+
async fn contact_name(&self) -> &String {
38+
&self.contact_name
39+
}
40+
41+
async fn contact_email(&self) -> &String {
42+
&self.contact_email
43+
}
44+
45+
async fn contact_phone(&self) -> &String {
46+
&self.contact_phone
47+
}
48+
49+
async fn website(&self) -> &Option<String> {
50+
&self.website
51+
}
52+
53+
async fn created_at(&self) -> &chrono::DateTime<chrono::Utc> {
54+
&self.created_at
55+
}
56+
57+
async fn updated_at(&self) -> &chrono::DateTime<chrono::Utc> {
58+
&self.updated_at
59+
}
60+
}
61+
62+
// Manual GraphQL SimpleObject implementation for PaginationResult<Suppliers>
63+
// This is needed because dsync disabled GraphQL generation for suppliers
64+
#[derive(SimpleObject)]
65+
#[graphql(name = "SupplierPaginationResult")]
66+
pub struct SupplierPaginationResult {
67+
/// Resulting items that are from the current page
68+
pub items: Vec<Suppliers>,
69+
/// The count of total items there are
70+
pub total_items: i64,
71+
/// Current page, 0-based index
72+
pub page: i64,
73+
/// Size of a page
74+
pub page_size: i64,
75+
/// Number of total possible pages, given the `page_size` and `total_items`
76+
pub num_pages: i64,
77+
}
78+
79+
impl From<PaginationResult<Suppliers>> for SupplierPaginationResult {
80+
fn from(result: PaginationResult<Suppliers>) -> Self {
81+
Self {
82+
items: result.items,
83+
total_items: result.total_items,
84+
page: result.page,
85+
page_size: result.page_size,
86+
num_pages: result.num_pages,
87+
}
88+
}
89+
}

backend/models/suppliers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
pub mod generated;
2+
pub mod graphql;
3+
24
pub use generated::*;
5+
pub use graphql::SupplierPaginationResult;

frontend/src/App.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import './App.css'
1414
import { Home } from './containers/Home'
1515
import { Todos } from './containers/Todo'
1616
import { TodoGraphQLRelay } from './containers/TodoGraphQLRelay'
17+
import { SupplierList } from './containers/SupplierList'
1718
import { Files } from './containers/Files'
1819
import { Route, useNavigate, Routes } from 'react-router-dom'
1920

@@ -35,6 +36,7 @@ const App = () => {
3536
<a className="NavButton" onClick={() => navigate('/')}>Home</a>
3637
<a className="NavButton" onClick={() => navigate('/todos')}>Todos (REST)</a>
3738
<a className="NavButton" onClick={() => navigate('/todos-relay')}>Todos (Relay)</a>
39+
<a className="NavButton" onClick={() => navigate('/suppliers')}>Suppliers</a>
3840
<a className="NavButton" onClick={() => navigate('/files')}>Files</a>
3941
{/* CRA: left-aligned nav buttons */}
4042
<a className="NavButton" onClick={() => navigate('/account')}>Account</a>
@@ -70,6 +72,11 @@ const App = () => {
7072
<TodoGraphQLRelay />
7173
</Suspense>
7274
} />
75+
<Route path="/suppliers" element={
76+
<Suspense fallback={<div>Loading suppliers...</div>}>
77+
<SupplierList />
78+
</Suspense>
79+
} />
7380
{/* CRA: routes */}
7481
<Route path="/files" element={<Files />} />
7582
<Route path="/login" element={<LoginPage />} />

0 commit comments

Comments
 (0)