Skip to content

Commit 4bc28a6

Browse files
committed
readme
1 parent a04335f commit 4bc28a6

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/convex-helpers/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ See the associated [Stack Post](https://stack.convex.dev/custom-functions)
5252

5353
For example:
5454

55-
```js
55+
```ts
5656
import { customQuery } from "convex-helpers/server/customFunctions.js";
5757

5858
const myQueryBuilder = customQuery(query, {
@@ -75,6 +75,34 @@ export const getSomeData = myQueryBuilder({
7575
});
7676
```
7777

78+
### Taking in extra arguments
79+
80+
You can take in extra arguments to a custom function by specifying the type of a third `input` arg.
81+
82+
```ts
83+
const myQueryBuilder = customQuery(query, {
84+
args: { },
85+
input: async (ctx, args, { role }: { role: "admin" | "user" }) => {
86+
const user = await getUser(ctx);
87+
if (role === "admin" && user.role !== "admin") {
88+
throw new Error("You are not an admin");
89+
}
90+
if (role === "user" && !user) {
91+
throw new Error("You must be logged in to access this query");
92+
}
93+
return { ctx: { user }, args: {} };
94+
}
95+
});
96+
97+
const myAdminQuery = myQueryBuilder({
98+
role: "admin",
99+
args: { },
100+
handler: async (ctx, args) => {
101+
// ...
102+
},
103+
});
104+
```
105+
78106
## Relationship helpers
79107

80108
Traverse database relationships without all the query boilerplate.

0 commit comments

Comments
 (0)