Using Wasp Mage to generate and update new Wasp entity Actions and Queries

I am interested to know if we have a way to use the wasp mage to generate our project's actions and queries dynamically. I want to update my wasp.main file, and run wasp clean, and them wasp make to generate updated actions and sensible queries.
4 Replies
kapa.ai
kapa.ai8mo ago
Hi @2b|¬2b. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry for the confusion, but there seems to be a misunderstanding. Wasp doesn't have a feature called "Wasp Mage" for generating actions and queries dynamically. However, Wasp does provide a way to define actions and queries in your .wasp file and implement them in your src/ directory. To define an action or a query, you need to add an action or query declaration in your .wasp file. For example:
action createTask {
fn: import { createTask } from "@src/actions.js",
entities: [Task]
}

query getTasks {
fn: import { getTasks } from "@src/queries",
entities: [Task]
}
action createTask {
fn: import { createTask } from "@src/actions.js",
entities: [Task]
}

query getTasks {
fn: import { getTasks } from "@src/queries",
entities: [Task]
}
source (https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions) Then, you implement these actions or queries in your src/ directory. For example:
export const createTask = async (args, context) => {
const newTask = await context.entities.Task.create({
data: {
description: args.description,
isDone: false,
},
})
return newTask
}

export const getTasks = async (args, context) => {
// Implementation here
}
export const createTask = async (args, context) => {
const newTask = await context.entities.Task.create({
data: {
description: args.description,
isDone: false,
},
})
return newTask
}

export const getTasks = async (args, context) => {
// Implementation here
}
source (https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions) After defining and implementing your actions and queries, you can use the wasp start command to launch your Wasp app in development mode. This command automatically watches for any changes to .wasp or files in src/ and reflects them in the browser.
wasp start
wasp start
source (https://wasp-lang.dev/docs/general/cli#project-commands) If you want to clean your project, you can use the wasp clean command. This command removes all generated code and other cached artifacts.
wasp clean
wasp clean
source (https://wasp-lang.dev/docs/general/cli#project-commands) However, Wasp doesn't provide a wasp make command or a similar feature for automatically generating updated actions and queries based on your .wasp file. You need to manually define and implement your actions and queries as described above. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @2b|¬2b, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
martinsos
martinsos8mo ago
@2b|¬2b I am not sure I get the idea. Do you mean you would like to write action/query declarations in main.wasp, and then have Wasp AI generate the implementation in JS for you? Or are you referring to something else? Mage itself can currently only generate an app from scratch for you: it can't then add more stuff to it (for now).
2b|¬2b
2b|¬2bOP8mo ago
Ah I just answered my question now and the solution was... read the docs Can we delete this thread lol
martinsos
martinsos8mo ago
Oh hey great! I am intersted though, what was the answer? It might help someone else
Want results from more Discord servers?
Add your server