Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit ad704f4

Browse files
authored
chore: rename query function to proceed for onquery plugin (#167)
* chore: rename query function to proceed for onquery plugin * update test
1 parent b57827a commit ad704f4

6 files changed

Lines changed: 27 additions & 27 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ ORM query interception allows you to intercept the high-level ORM API calls. The
289289
```ts
290290
db.$use({
291291
id: 'cost-logger',
292-
onQuery: async ({ model, operation, args, query }) => {
292+
onQuery: async ({ model, operation, args, proceed }) => {
293293
const start = Date.now();
294-
const result = await query(args);
294+
const result = await proceed(args);
295295
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
296296
return result;
297297
},

packages/runtime/src/client/client-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function createModelCrudHandler<Schema extends SchemaDef, Model extends GetModel
379379
const onQuery = plugin.onQuery;
380380
if (onQuery) {
381381
const _proceed = proceed;
382-
proceed = () => onQuery({ client, model, operation, args, query: _proceed }) as Promise<unknown>;
382+
proceed = () => onQuery({ client, model, operation, args, proceed: _proceed }) as Promise<unknown>;
383383
}
384384
}
385385

packages/runtime/src/client/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
6969
args: unknown;
7070

7171
/**
72-
* The query function to proceed with the original query.
72+
* The function to proceed with the original query.
7373
* It takes the same arguments as the operation method.
7474
*
7575
* @param args The query arguments.
7676
*/
77-
query: (args: unknown) => Promise<unknown>;
77+
proceed: (args: unknown) => Promise<unknown>;
7878

7979
/**
8080
* The ZenStack client that is performing the operation.

packages/runtime/test/plugin/on-query-hooks.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('On query hooks tests', () => {
3535
} else if (ctx.operation === 'update') {
3636
updateHookCalled = true;
3737
}
38-
return ctx.query(ctx.args);
38+
return ctx.proceed(ctx.args);
3939
},
4040
});
4141

@@ -61,7 +61,7 @@ describe('On query hooks tests', () => {
6161
hooksCalled = true;
6262
expect(ctx.model).toBe('User');
6363
}
64-
return ctx.query(ctx.args);
64+
return ctx.proceed(ctx.args);
6565
},
6666
});
6767
await expect(
@@ -84,7 +84,7 @@ describe('On query hooks tests', () => {
8484
hooksCalled = true;
8585
expect(ctx.model).toBe('User');
8686
expect(ctx.operation).toBe('findFirst');
87-
return ctx.query(ctx.args);
87+
return ctx.proceed(ctx.args);
8888
},
8989
});
9090
await expect(
@@ -106,9 +106,9 @@ describe('On query hooks tests', () => {
106106
onQuery: async (ctx) => {
107107
if (ctx.model === 'User' && ctx.operation === 'findFirst') {
108108
hooksCalled = true;
109-
return ctx.query({ where: { id: 'non-exist' } });
109+
return ctx.proceed({ where: { id: 'non-exist' } });
110110
} else {
111-
return ctx.query(ctx.args);
111+
return ctx.proceed(ctx.args);
112112
}
113113
},
114114
});
@@ -132,11 +132,11 @@ describe('On query hooks tests', () => {
132132
onQuery: async (ctx) => {
133133
if (ctx.model === 'User' && ctx.operation === 'findFirst') {
134134
hooksCalled = true;
135-
const result = await ctx.query(ctx.args);
135+
const result = await ctx.proceed(ctx.args);
136136
(result as any).happy = true;
137137
return result;
138138
} else {
139-
return ctx.query(ctx.args);
139+
return ctx.proceed(ctx.args);
140140
}
141141
},
142142
});
@@ -159,10 +159,10 @@ describe('On query hooks tests', () => {
159159
onQuery: async (ctx) => {
160160
if (ctx.model === 'User' && ctx.operation === 'create') {
161161
hooksCalled = true;
162-
await ctx.query(ctx.args);
162+
await ctx.proceed(ctx.args);
163163
throw new Error('trigger error');
164164
} else {
165-
return ctx.query(ctx.args);
165+
return ctx.proceed(ctx.args);
166166
}
167167
},
168168
});
@@ -194,7 +194,7 @@ describe('On query hooks tests', () => {
194194
id: 'test-plugin',
195195
onQuery: (ctx) => {
196196
findHookCalled = true;
197-
return ctx.query(ctx.args);
197+
return ctx.proceed(ctx.args);
198198
},
199199
});
200200

packages/runtime/test/policy/client-extensions.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe('client extensions tests for policies', () => {
2323

2424
const ext = definePlugin({
2525
id: 'prisma-extension-queryOverride',
26-
onQuery: async ({ args, query }: any) => {
26+
onQuery: async ({ args, proceed }: any) => {
2727
args = args ?? {};
2828
args.where = { ...args.where, y: { lt: 300 } };
29-
return query(args);
29+
return proceed(args);
3030
},
3131
});
3232

@@ -54,10 +54,10 @@ describe('client extensions tests for policies', () => {
5454

5555
const ext = definePlugin({
5656
id: 'prisma-extension-queryOverride',
57-
onQuery: async ({ args, query }: any) => {
57+
onQuery: async ({ args, proceed }: any) => {
5858
args = args ?? {};
5959
args.where = { ...args.where, y: { lt: 300 } };
60-
return query(args);
60+
return proceed(args);
6161
},
6262
});
6363

@@ -85,10 +85,10 @@ describe('client extensions tests for policies', () => {
8585

8686
const ext = definePlugin({
8787
id: 'prisma-extension-queryOverride',
88-
onQuery: async ({ args, query }: any) => {
88+
onQuery: async ({ args, proceed }: any) => {
8989
args = args ?? {};
9090
args.where = { ...args.where, y: { lt: 300 } };
91-
return query(args);
91+
return proceed(args);
9292
},
9393
});
9494

@@ -116,10 +116,10 @@ describe('client extensions tests for policies', () => {
116116

117117
const ext = definePlugin({
118118
id: 'prisma-extension-queryOverride',
119-
onQuery: async ({ args, query }: any) => {
119+
onQuery: async ({ args, proceed }: any) => {
120120
args = args ?? {};
121121
args.where = { ...args.where, y: { lt: 300 } };
122-
return query(args);
122+
return proceed(args);
123123
},
124124
});
125125

@@ -145,8 +145,8 @@ describe('client extensions tests for policies', () => {
145145

146146
const ext = definePlugin({
147147
id: 'prisma-extension-resultMutation',
148-
onQuery: async ({ args, query }: any) => {
149-
const r: any = await query(args);
148+
onQuery: async ({ args, proceed }: any) => {
149+
const r: any = await proceed(args);
150150
for (let i = 0; i < r.length; i++) {
151151
r[i].value = r[i].value + 1;
152152
}

samples/blog/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ async function main() {
1717
},
1818
}).$use({
1919
id: 'cost-logger',
20-
onQuery: async ({ model, operation, args, query }) => {
20+
onQuery: async ({ model, operation, args, proceed }) => {
2121
const start = Date.now();
22-
const result = await query(args);
22+
const result = await proceed(args);
2323
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
2424
return result;
2525
},

0 commit comments

Comments
 (0)