Query Typescript

I have the following code in my main.wasp:
query getIdeas {
// We specify that JS implementation of the query (which is an async JS function)
// can be found in `src/server/queries.js` as the named export `getTasks`.
// Use '@server' to reference files inside the src/server folder.
fn: import { getIdeas } from "@server/queries.js",
// We tell Wasp that this query is doing something with entity `Task`. With that, Wasp will
// automatically refresh the results of this query when tasks change.
entities: [Idea]
}
query getIdeas {
// We specify that JS implementation of the query (which is an async JS function)
// can be found in `src/server/queries.js` as the named export `getTasks`.
// Use '@server' to reference files inside the src/server folder.
fn: import { getIdeas } from "@server/queries.js",
// We tell Wasp that this query is doing something with entity `Task`. With that, Wasp will
// automatically refresh the results of this query when tasks change.
entities: [Idea]
}
And query.ts:
export const getIdeas = async (args, context) => {
return context.entities.Idea.findMany({});
};
export const getIdeas = async (args, context) => {
return context.entities.Idea.findMany({});
};
Do Wasp have a type to have typescript types on the args and context ?
4 Replies
matijash
matijash2y ago
yes! check out this example:
No description
matijash
matijash2y ago
so args you can specify yourself as you wish (either create a custom type or use one from the entity), and context is automatically inferred from the query definition in .wasp config
matijash
matijash2y ago
TypeScript Support | Wasp
TypeScript is a programming language that brings static type analysis to JavaScript. It is a superset of JavaScript (i.e., all valid JavaScript programs are valid TypeScript programs) and compiles to JavaScript before running. TypeScript's type system detects common errors at build time (reducing the chance of runtime errors in production) and e...
0xtlt
0xtltOP2y ago
Ah super thank you!
Want results from more Discord servers?
Add your server