File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ See the associated [Stack Post](https://stack.convex.dev/custom-functions)
5252
5353For example:
5454
55- ``` js
55+ ``` ts
5656import { customQuery } from " convex-helpers/server/customFunctions.js" ;
5757
5858const 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
80108Traverse database relationships without all the query boilerplate.
You can’t perform that action at this time.
0 commit comments