From ec015c13576dd3ab2e53209e3587c57bd61de67f Mon Sep 17 00:00:00 2001 From: Martin Sosic Date: Tue, 1 Dec 2020 18:48:39 +0100 Subject: [PATCH] Final polishing of first version of RWA. --- examples/realworld/README.md | 1 + examples/realworld/ext/Navbar.js | 2 +- examples/realworld/ext/article/queries.js | 2 +- examples/realworld/ext/auth/SignupPage.js | 4 ++-- examples/realworld/ext/user/actions.js | 16 ---------------- examples/realworld/main.wasp | 23 ++++++++++++++--------- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/examples/realworld/README.md b/examples/realworld/README.md index 5bcd3f605..ae3261445 100644 --- a/examples/realworld/README.md +++ b/examples/realworld/README.md @@ -53,3 +53,4 @@ Thoughts while implementing the RWA: - Pagination, although so common, demanded non-trivial effort and attention. Since pagination is full-stack feature, I am pretty sure we could offer some support here through Wasp and simplify it / provide something out of the box. There are two types of pagination we should take into consideration: skip+take and cursor-based. - I had a situation where I had the operation dealing with entity E2 but E2 did not have to be provided under "entities" in Wasp becuause through Prisma nesting it was accessed through E1. However, I still wanted cache invalidation to work on frontend so I added E2 under "entities". Situation could also be opposite: we might need to provide E2 under "entities" to do some operation, although we know it does not affect cache invalidation. It might be interesting in the future to give more attention to this and make sure Wasp does its best to provide smooth experience in these situations -> maybe by some special support. - Wasp file ended up really big and hard to navigate! Even if we don't have a real module support, just splitting it into multiple files that are then merged together might be a good start (and it might work since order is not important so far). +- Would be cool if not each action had to be imported as a separate import statement, but maybe all in one statement. diff --git a/examples/realworld/ext/Navbar.js b/examples/realworld/ext/Navbar.js index 25678b33e..357e21aa7 100644 --- a/examples/realworld/ext/Navbar.js +++ b/examples/realworld/ext/Navbar.js @@ -13,7 +13,7 @@ const Navbar = () => { Home New Article Settings - { user.username } + { user.username } ) } else { diff --git a/examples/realworld/ext/article/queries.js b/examples/realworld/ext/article/queries.js index f00b0ab42..cea9004b9 100644 --- a/examples/realworld/ext/article/queries.js +++ b/examples/realworld/ext/article/queries.js @@ -5,7 +5,7 @@ import { userPublicSelection } from '../user/queries.js' // TODO: I extracted this articleInclude and articleSetFavoritedFields to enable // reusing of logic that shapes articles as they come out of the server, // but I wonder if there is a more elegant way - here there are a lot of assumptions, -// and it is easy to not use where it should be used or use it in wrong setting. +// and it is easy to not use where it should be used or use it in a wrong setting. const articleInclude = { user: { diff --git a/examples/realworld/ext/auth/SignupPage.js b/examples/realworld/ext/auth/SignupPage.js index 159e0f0e9..455e7ebd4 100644 --- a/examples/realworld/ext/auth/SignupPage.js +++ b/examples/realworld/ext/auth/SignupPage.js @@ -1,8 +1,8 @@ import React, { useState } from 'react' import { useHistory } from 'react-router-dom' -import login from '@wasp/auth/login.js' -import signup from '@wasp/actions/signup' +import login from '@wasp/auth/login' +import signup from '@wasp/auth/signup' export default () => { const history = useHistory() diff --git a/examples/realworld/ext/user/actions.js b/examples/realworld/ext/user/actions.js index 99d282db7..218bde455 100644 --- a/examples/realworld/ext/user/actions.js +++ b/examples/realworld/ext/user/actions.js @@ -1,21 +1,5 @@ import HttpError from '@wasp/core/HttpError.js' -export const signup = async ({ username, email, password }, context) => { - try { - console.log(username, email, password) - return await context.entities.User.create({ - data: { username, email, password } - }) - } catch (err) { - // TODO: I wish I didn't have to do this, I would love this to be in some - // degree done automatically. - if (err.code == 'P2002') { - throw new HttpError(400, err.meta.target + " must be unique.") - } - throw err - } -} - export const updateUser = async ({ email, username, bio, profilePictureUrl, newPassword }, context) => { if (!context.user) { throw new HttpError(403) } diff --git a/examples/realworld/main.wasp b/examples/realworld/main.wasp index 9e7df1de6..698010071 100644 --- a/examples/realworld/main.wasp +++ b/examples/realworld/main.wasp @@ -2,6 +2,13 @@ app Conduit { title: "Conduit" } +auth { + userEntity: User, + methods: [ EmailAndPassword ] +} + +// ----------------- Pages ------------------ // + route "/" -> page Main page Main { component: import Main from "@ext/MainPage.js" @@ -41,6 +48,8 @@ page ArticleView { component: import ArticleView from "@ext/article/components/ArticleViewPage.js" } +// ----------------- Entities ------------------ // + entity User {=psl id Int @id @default(autoincrement()) username String @unique @@ -89,21 +98,13 @@ entity ArticleTag {=psl articles Article[] psl=} -auth { - userEntity: User, - methods: [ EmailAndPassword ] -} +// ----------------- User operations ------------------ // query getUser { fn: import { getUser } from "@ext/user/queries.js", entities: [User] } -action signup { - fn: import { signup } from "@ext/user/actions.js", - entities: [User] -} - action updateUser { fn: import { updateUser } from "@ext/user/actions.js", entities: [User] @@ -114,6 +115,8 @@ action followUser { entities: [User] } +// ----------------- Article operations ------------------ // + query getArticlesByUser { fn: import { getArticlesByUser } from "@ext/article/queries.js", entities: [Article] @@ -179,6 +182,8 @@ query getTags { entities: [ArticleTag, Article] } +// -------------------------------------------- // + dependencies {=json "prop-types": "15.7.2", "react-markdown": "5.0.3",