diff --git a/web/docs/language/features.md b/web/docs/language/features.md index e8ed1b51c..538831c96 100644 --- a/web/docs/language/features.md +++ b/web/docs/language/features.md @@ -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 diff --git a/web/docs/tutorials/todo-app/06-auth.md b/web/docs/tutorials/todo-app/06-auth.md index c0187ee9c..d6218143c 100644 --- a/web/docs/tutorials/todo-app/06-auth.md +++ b/web/docs/tutorials/todo-app/06-auth.md @@ -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 ( diff --git a/web/docs/typescript.md b/web/docs/typescript.md index 24a034caa..f67b30af4 100644 --- a/web/docs/typescript.md +++ b/web/docs/typescript.md @@ -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!",