Small docs fixes (#1175)

* Fix LoginForm and SignupForm imports in 06-auth.md (#1156)

* Fix docs for async queries

---------

Co-authored-by: Phillip Cutter <mrfleap@gmail.com>
This commit is contained in:
Filip Sodić 2023-05-02 10:00:06 +02:00 committed by GitHub
parent 683c4fd43c
commit 9d947c5a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 13 deletions

View File

@ -228,13 +228,13 @@ After completing these two steps, you'll be able to use the Query from any point
#### Defining the Query's NodeJS implementation
A Query must be implemented as an `async` NodeJS function that takes two arguments.
The Query's implementation is a NodeJS function that takes two arguments (it can be an `async` function but doesn't have to).
Since both arguments are positional, you can name the parameters however you want, but we'll stick with `args` and `context`:
1. `args`: An object containing all the arguments (i.e., payload) **passed to the Query by the caller** (e.g., filtering conditions).
Take a look at [the examples of usage](#using-the-query) to see how to pass this object to the Query.
3. `context`: An additional context object **injected into the Query by Wasp**. This object contains user session information, as well as information about entities. The examples here won't use the context for simplicity purposes. You can read more about it in the [section about using entities in queries](#using-entities-in-queries).
Here's an example of two simple Queries:
Here's an example of three simple Queries:
```js title="src/server/queries.js"
// our "database"
const tasks = [
@ -243,17 +243,22 @@ const tasks = [
{ id: 3, description: "Eat breakfast", isDone: false }
]
// You don't need to use the arguments if you don't need them
export const getAllTasks = async () => {
export const getAllTasks = () => {
return tasks;
}
// The 'args' object is something sent by the caller (most often from the client)
export const getFilteredTasks = async (args) => {
export const getFilteredTasks = (args) => {
const { isDone } = args;
return tasks.filter(task => task.isDone === isDone)
}
// Query implementations can be async functions and use await.
export const getTasksWithDelay = async () => {
const result = await sleep(1000)
return tasks
}
```
#### Declaring a Query in Wasp
@ -452,10 +457,10 @@ Here's an example on how you might define a less contrived Action.
```js title=src/server/actions.js
// ...
export const updateTaskIsDone = ({ id, isDone }, context) => {
return context.entities.Task.update({
where: { id },
data: { isDone }
})
return context.entities.Task.update({
where: { id },
data: { isDone }
})
}
```
```c title=main.wasp

View File

@ -95,7 +95,7 @@ Great, Wasp now knows how to route these and where to find the pages. Now to the
```jsx title="src/client/LoginPage.jsx"
import { Link } from 'react-router-dom'
import LoginForm from '@wasp/auth/forms/Login'
import { LoginForm } from '@wasp/auth/forms/Login'
const LoginPage = () => {
return (
@ -117,7 +117,7 @@ The Signup page is very similar to the login one:
```jsx title="src/client/SignupPage.jsx"
import { Link } from 'react-router-dom'
import SignupForm from '@wasp/auth/forms/Signup'
import { SignupForm } from '@wasp/auth/forms/Signup'
const SignupPage = () => {
return (

View File

@ -219,8 +219,8 @@ Everything described above applies to Actions as well.
If don't want to define a new type for the Query's return value, the new `satisfies` keyword will allow TypeScript to infer it automatically:
```typescript
const getFoo = ((_args, context) => {
const foos = context.entities.Foo.findMany()
const getFoo = (async (_args, context) => {
const foos = await context.entities.Foo.findMany()
return {
foos,
message: "Here are some foos!",