mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-28 11:34:41 +03:00
Add extendedWhereUnique to Wasp AI
This commit is contained in:
parent
4bff9069a3
commit
ba683d0969
@ -72,7 +72,15 @@ waspFileExample =
|
||||
userEntity: User,
|
||||
methods: { usernameAndPassword: {} },
|
||||
onAuthFailedRedirectTo: "/login"
|
||||
}
|
||||
},
|
||||
client: {
|
||||
rootComponent: import { Layout } from "@client/Layout.jsx",
|
||||
},
|
||||
db: {
|
||||
prisma: {
|
||||
clientPreviewFeatures: ["extendedWhereUnique"]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
route SignupRoute { path: "/signup", to: SignupPage }
|
||||
|
@ -109,24 +109,6 @@ generateOperation operationType newProjectDetails entityPlans operationPlan = do
|
||||
Also, make sure to use full import statement for `fn:`: `import { getTasks } from "@server/actions.js"`,
|
||||
don't provide just the file path.
|
||||
- In NodeJS implementation, you will typically want to check if user is authenticated, by doing `if (!context.user) { throw new HttpError(401) }` at the start of the operation.
|
||||
- DO NOT specify more than one field in the `where` clause of `update()` and `findUnique()` Prisma methods.
|
||||
Unlike other Prisma methods, these two can accept only one, unique field in their `where` clause.
|
||||
WRONG:
|
||||
```js
|
||||
const task = await context.entities.Task.findUnique({
|
||||
where: {
|
||||
id: args.id,
|
||||
userId: context.user.id
|
||||
}
|
||||
});
|
||||
```
|
||||
CORRECT:
|
||||
```js
|
||||
const task = await context.entities.Task.findUnique({
|
||||
where: { id: args.id }
|
||||
});
|
||||
if (task.userId !== context.user.id) { throw new HttpError(403) };
|
||||
```
|
||||
|
||||
${appDescriptionStartMarkerLine}
|
||||
|
||||
|
@ -71,9 +71,6 @@ fixOperationsJsFile newProjectDetails waspFilePath opJsFilePath = do
|
||||
- Duplicate imports. If there are any, make sure to remove them.
|
||||
- js imports of local modules (`from "./`, `from "../`).
|
||||
If there are any, remove them and instead add the needed implementation directly into the file we are fixing right now.
|
||||
- Providing more than one field in the `where` clause of `update()` and `findUnique()` Prisma methods.
|
||||
Unlike other Prisma methods, these two can accept only one, unique field in their `where` clause.
|
||||
If this mistake is present, refactor the code so that it still works as intended but has just one field in the `where` clause.
|
||||
- Redundant imports of prisma client or of prisma entities. Those imports are not needed -> remove them!
|
||||
|
||||
We are not using PrismaClient directly, we are using it through the context. For example: `context.entities.Task.findMany({})`
|
||||
|
@ -87,6 +87,11 @@ generateBaseWaspFile newProjectDetails = ((path, content), planRules)
|
||||
client: {
|
||||
rootComponent: import { Layout } from "@client/Layout.jsx",
|
||||
},
|
||||
db: {
|
||||
prisma: {
|
||||
clientPreviewFeatures: ["extendedWhereUnique"]
|
||||
}
|
||||
},
|
||||
${appAuth}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import System.Exit (ExitCode (..))
|
||||
import qualified System.Process as P
|
||||
import qualified Wasp.Package as WP
|
||||
import qualified Wasp.NodePackageFFI as WP
|
||||
import Wasp.Util.Aeson (decodeFromString)
|
||||
|
||||
-- | For given prisma schema source, returns formatted schema + any warnings/errors,
|
||||
@ -25,7 +25,7 @@ import Wasp.Util.Aeson (decodeFromString)
|
||||
-- It works even for a prisma schema that has only model declarations!
|
||||
prismaFormat :: Text -> IO PrismaFormatResult
|
||||
prismaFormat prismaSchema = do
|
||||
cp <- WP.getPackageProc WP.PrismaPackage ["format"]
|
||||
cp <- WP.getPackageProcessOptions WP.PrismaPackage ["format"]
|
||||
(exitCode, response, stderr) <- P.readCreateProcessWithExitCode cp $ T.unpack prismaSchema
|
||||
case exitCode of
|
||||
ExitSuccess ->
|
||||
|
Loading…
Reference in New Issue
Block a user