@@ -228,6 +228,7 @@ builder.drizzleObject('users', {
228228 limit: t .arg .int (),
229229 offset: t .arg .int (),
230230 },
231+ // query callback receives (args, ctx, pathInfo)
231232 query : (args ) => ({
232233 limit: args .limit ?? 10 ,
233234 offset: args .offset ?? 0 ,
@@ -251,71 +252,9 @@ builder.drizzleObject('users', {
251252```
252253
253254The query API enables you to define args and convert them into parameters that will be passed into
254- the relational query builder. You can read more about the relation query builder api
255- [ here] ( https://orm.drizzle.team/docs/rqb#querying )
256-
257- ### Path-based filtering
258-
259- The query callback also receives a ` pathInfo ` parameter that provides information about the GraphQL
260- query path. This enables filtering based on how a field is accessed in the query:
261-
262- ``` ts
263- builder .drizzleObject (' users' , {
264- name: ' User' ,
265- fields : (t ) => ({
266- // This field returns different results based on the query path
267- posts: t .relation (' posts' , {
268- query : (args , ctx , pathInfo ) => {
269- // pathInfo.path = ['Query.pendingReviewAuthor', 'User.posts']
270- // Check if we're accessed via the pendingReviewAuthor query
271- const isReviewContext = pathInfo ?.path ?.at (- 2 ) === ' Query.pendingReviewAuthor' ;
272-
273- return {
274- where: {
275- // Show drafts in review context, published posts otherwise
276- published: isReviewContext ? false : true ,
277- },
278- orderBy: { updatedAt: ' desc' },
279- };
280- },
281- }),
282- }),
283- });
284- ```
285-
286- The ` pathInfo ` object contains:
287-
288- - ` path ` : Array of ` "ParentType.fieldName" ` strings representing the query path (e.g.,
289- ` ['Query.user', 'User.posts'] ` )
290- - ` segments ` : Detailed info for each path segment with ` field ` , ` alias ` , ` parentType ` , and ` isList `
291- properties
292-
293- This is useful when you want the same relation field to behave differently depending on the context
294- in which it's queried. The ` t.relatedConnection ` method also supports ` pathInfo ` in its query
295- callback.
296-
297- ### Path info on nestedSelection
298-
299- When using ` t.field ` with a ` select ` callback function, path information is also available on the
300- ` nestedSelection ` function:
301-
302- ``` ts
303- builder .drizzleObject (' users' , {
304- name: ' User' ,
305- fields : (t ) => ({
306- customField: t .field ({
307- type: SomeType ,
308- select : (args , ctx , nestedSelection ) => {
309- // Access path info from the nestedSelection function
310- console .log (nestedSelection .path ); // ['Query.user', 'User.customField']
311- console .log (nestedSelection .segments ); // [{ field, alias, parentType, isList }, ...]
312-
313- return nestedSelection ({ columns: { id: true } });
314- },
315- resolve : (parent ) => parent ,
316- }),
317- }),
318- });
255+ the relational query builder. The ` query ` callback receives ` (args, ctx, pathInfo) ` where ` pathInfo `
256+ contains the GraphQL query path information (` path ` and ` segments ` ). You can read more about the
257+ relation query builder api [ here] ( https://orm.drizzle.team/docs/rqb#querying )
319258
320259## Drizzle Fields
321260
0 commit comments