@pothos/plugin-prisma 3.7.0 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +191 -100
  3. package/dts/global-types.d.ts +2 -2
  4. package/dts/global-types.d.ts.map +1 -1
  5. package/dts/index.d.ts.map +1 -1
  6. package/dts/model-loader.d.ts +13 -2
  7. package/dts/model-loader.d.ts.map +1 -1
  8. package/dts/node-ref.d.ts.map +1 -1
  9. package/dts/object-ref.d.ts.map +1 -1
  10. package/dts/prisma-field-builder.d.ts +7 -7
  11. package/dts/prisma-field-builder.d.ts.map +1 -1
  12. package/dts/types.d.ts +19 -9
  13. package/dts/types.d.ts.map +1 -1
  14. package/dts/util/cursors.d.ts +5 -1
  15. package/dts/util/cursors.d.ts.map +1 -1
  16. package/dts/util/datamodel.d.ts +5 -1
  17. package/dts/util/datamodel.d.ts.map +1 -1
  18. package/dts/util/get-client.d.ts +5 -1
  19. package/dts/util/get-client.d.ts.map +1 -1
  20. package/dts/util/loader-map.d.ts +2 -2
  21. package/dts/util/loader-map.d.ts.map +1 -1
  22. package/dts/util/map-query.d.ts.map +1 -1
  23. package/esm/field-builder.js.map +1 -1
  24. package/esm/generator.js.map +1 -1
  25. package/esm/global-types.js.map +1 -1
  26. package/esm/index.js +5 -7
  27. package/esm/index.js.map +1 -1
  28. package/esm/model-loader.js +88 -3
  29. package/esm/model-loader.js.map +1 -1
  30. package/esm/node-ref.js.map +1 -1
  31. package/esm/prisma-field-builder.js +29 -24
  32. package/esm/prisma-field-builder.js.map +1 -1
  33. package/esm/schema-builder.js +24 -16
  34. package/esm/schema-builder.js.map +1 -1
  35. package/esm/util/cursors.js +95 -2
  36. package/esm/util/cursors.js.map +1 -1
  37. package/esm/util/datamodel.js.map +1 -1
  38. package/esm/util/get-client.js.map +1 -1
  39. package/esm/util/loader-map.js +2 -3
  40. package/esm/util/loader-map.js.map +1 -1
  41. package/esm/util/map-query.js +47 -9
  42. package/esm/util/map-query.js.map +1 -1
  43. package/esm/util/relation-map.js.map +1 -1
  44. package/esm/util/selections.js.map +1 -1
  45. package/lib/field-builder.js +3 -6
  46. package/lib/field-builder.js.map +1 -1
  47. package/lib/generator.js +8 -16
  48. package/lib/generator.js.map +1 -1
  49. package/lib/index.js +6 -21
  50. package/lib/index.js.map +1 -1
  51. package/lib/model-loader.js +82 -3
  52. package/lib/model-loader.js.map +1 -1
  53. package/lib/node-ref.js +1 -2
  54. package/lib/node-ref.js.map +1 -1
  55. package/lib/prisma-field-builder.js +36 -40
  56. package/lib/prisma-field-builder.js.map +1 -1
  57. package/lib/schema-builder.js +25 -19
  58. package/lib/schema-builder.js.map +1 -1
  59. package/lib/util/cursors.js +100 -6
  60. package/lib/util/cursors.js.map +1 -1
  61. package/lib/util/datamodel.js +2 -4
  62. package/lib/util/datamodel.js.map +1 -1
  63. package/lib/util/get-client.js +1 -3
  64. package/lib/util/get-client.js.map +1 -1
  65. package/lib/util/loader-map.js +3 -5
  66. package/lib/util/loader-map.js.map +1 -1
  67. package/lib/util/map-query.js +47 -9
  68. package/lib/util/map-query.js.map +1 -1
  69. package/lib/util/relation-map.js +1 -2
  70. package/lib/util/relation-map.js.map +1 -1
  71. package/lib/util/selections.js +2 -4
  72. package/lib/util/selections.js.map +1 -1
  73. package/package.json +8 -8
  74. package/src/global-types.ts +3 -1
  75. package/src/index.ts +14 -4
  76. package/src/model-loader.ts +144 -3
  77. package/src/node-ref.ts +1 -1
  78. package/src/object-ref.ts +1 -1
  79. package/src/prisma-field-builder.ts +45 -26
  80. package/src/schema-builder.ts +25 -20
  81. package/src/types.ts +52 -10
  82. package/src/util/cursors.ts +117 -1
  83. package/src/util/get-client.ts +2 -1
  84. package/src/util/loader-map.ts +3 -9
  85. package/src/util/map-query.ts +66 -3
  86. package/tsconfig.type.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 384b0fb6: Make findUnique optional by defaulting to id/unique fields defined in prisma schema
8
+
9
+ ## 3.9.0
10
+
11
+ ### Minor Changes
12
+
13
+ - e090a835: Add fieldWithSelection method to support indirect relions
14
+
15
+ ### Patch Changes
16
+
17
+ - 4e5756ca: Update dev dependencies
18
+
19
+ ## 3.8.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 4154edc9: Add isNull option to prisma variant fields
24
+
3
25
  ## 3.7.0
4
26
 
5
27
  ### Minor Changes
package/README.md CHANGED
@@ -30,9 +30,6 @@ breakdown of what the methods and options used in the example below.
30
30
  // Create an object type based on a prisma model
31
31
  // without providing any custom type information
32
32
  builder.prismaObject('User', {
33
- // findUnique is explained more below, and is
34
- // required to safely resolve queries in some edge cases
35
- findUnique: (user) => ({ id: user.id }),
36
33
  fields: (t) => ({
37
34
  // expose fields from the database
38
35
  id: t.exposeID('id'),
@@ -74,8 +71,7 @@ builder.prismaObject('User', {
74
71
 
75
72
  // Create a relay node based a prisma model
76
73
  builder.prismaNode('Post', {
77
- findUnique: (id) => ({ id }),
78
- id: { resolve: (post) => post.id },
74
+ id: { field: 'id' },
79
75
  fields: (t) => ({
80
76
  title: t.exposeString('title'),
81
77
  author: t.relation('author'),
@@ -141,9 +137,7 @@ query {
141
137
 
142
138
  Will result in 2 calls to prisma, one to resolve everything except `oldPosts`, and a second to
143
139
  resolve everything inside `oldPosts`. Prisma can only resolve each relation once in a single query,
144
- so we need a separate to handle the second `posts` relation. These additional queries will use the
145
- `findUnique` defined for the parent type to create a new efficient query to load any conflicting
146
- relations.
140
+ so we need a separate to handle the second `posts` relation.
147
141
 
148
142
  ## Install
149
143
 
@@ -212,11 +206,6 @@ const builder = new SchemaBuilder<{
212
206
  prisma: {
213
207
  client: prisma,
214
208
  },
215
- prisma: {
216
- client: (ctx) => prisma,
217
- // Because the prisma client is loaded dynamically, we need to explicitly pass the builder some information about the prisma schema
218
- dmmf: (prisma as unknown as { _dmmf: Prisma.DMMF.Document })._dmmf,
219
- },
220
209
  });
221
210
  ```
222
211
 
@@ -268,7 +257,6 @@ const builder = new SchemaBuilder<{
268
257
  builder.prismaObject('User', {
269
258
  // Optional name for the object, defaults to the name of the prisma model
270
259
  name: 'PostAuthor',
271
- findUnique: (user) => ({ id: user.id }),
272
260
  fields: (t) => ({
273
261
  id: t.exposeID('id'),
274
262
  email: t.exposeString('email'),
@@ -276,7 +264,6 @@ builder.prismaObject('User', {
276
264
  });
277
265
 
278
266
  builder.prismaObject('Post', {
279
- findUnique: (post) => ({ id: post.id }),
280
267
  fields: (t) => ({
281
268
  id: t.exposeID('id'),
282
269
  title: t.exposeString('title'),
@@ -288,8 +275,6 @@ So far, this is just creating some simple object types. They work just like any
288
275
  Pothos. The main advantage of this is that we get the type information without using object refs, or
289
276
  needing imports from prisma client.
290
277
 
291
- The `findUnique` option is described more below.
292
-
293
278
  ## Adding prisma fields to non-prisma objects (including Query and Mutation)
294
279
 
295
280
  There is a new `t.prismaField` method which can be used to define fields that resolve to your prisma
@@ -346,7 +331,6 @@ builder.queryType({
346
331
  });
347
332
 
348
333
  builder.prismaObject('User', {
349
- findUnique: (user) => ({ id: user.id }),
350
334
  fields: (t) => ({
351
335
  id: t.exposeID('id'),
352
336
  email: t.exposeString('email'),
@@ -355,7 +339,6 @@ builder.prismaObject('User', {
355
339
  });
356
340
 
357
341
  builder.prismaObject('Post', {
358
- findUnique: (post) => ({ id: post.id }),
359
342
  fields: (t) => ({
360
343
  id: t.exposeID('id'),
361
344
  title: t.exposeString('title'),
@@ -398,26 +381,24 @@ the `me` `prismaField` would receive something like the following as its query p
398
381
  ```
399
382
 
400
383
  This will work perfectly for the majority of queries. There are a number of edge cases that make it
401
- impossible to resolve everything in a single query. When this happens the `findUnique` option is
402
- used to ensure that everything is still loaded correctly, and split into as few efficient queries as
403
- possible.
384
+ impossible to resolve everything in a single query. When this happens Pothos will automatically
385
+ construct an additional query to ensure that everything is still loaded correctly, and split into as
386
+ few efficient queries as possible. This process is described in more detail below
404
387
 
405
- ### Find Unique
388
+ ### Fallback queryies
406
389
 
407
- The `findUnique` function will receive an instance of the prisma model the current type is defining,
408
- and should return an object that will be passed as a `where` in a `prisma.findUnique`. Generally,
409
- this will just be something like: `user => { id: user.id }` where `id` is the primary key for the
410
- table.
411
-
412
- When the prisma plugin encounters a query where the requirements for a field can not be satisfied,
413
- it will call findUnique for the current prisma model, and include or select all properties that are
414
- required for the fields that could not be resolved without an additional query.
390
+ There are some cases where data can not be pre-loaded by a prisma field. In these cases, pothos will
391
+ issue a `findUnique` query for the parent of any fields that were not pre-loaded, and select the
392
+ missing relations so those fields can be resolved with the correct data. These queries should be
393
+ very efficient, are batched by pothos to combine requirements for multiple fields into one query,
394
+ and batched by Prisma to combine multiple queries (in an n+1 situation) to a single sql query.
415
395
 
416
396
  The following are some edge cases that could cause an additional query to be necessary:
417
397
 
418
398
  - The parent object was not loaded through a field defined with `t.prismaField`, or `t.relation`
419
399
  - The root `prismaField` did not correctly spread the `query` arguments in is prisma call.
420
- - The query selects multiple fields that use the same relation with different queries
400
+ - The query selects multiple fields that use the same relation with different filters, sorting, or
401
+ limits
421
402
  - The query contains multiple aliases for the same relation field with different arguments in a way
422
403
  that results in different query options for the relation.
423
404
  - A relation field has a query that is incompatible with the default includes of the parent object
@@ -425,32 +406,6 @@ The following are some edge cases that could cause an additional query to be nec
425
406
  All of the above should be relatively uncommon in normal usage, but the plugin ensures that these
426
407
  types of edge cases are automatically handled when they do occur.
427
408
 
428
- ### Without Find Unique
429
-
430
- This is generally _NOT RECOMMENDED_, but you can set `findUnique` to null for some prisma objects.
431
- Doing this will prevent the plugin from resolving queries for conflicting relations. Because of
432
- this, you will need to provide a `resolve` method when defining relations, and some other options
433
- (like field level selects, described below) will not be available. This `resolve` method is _ONLY
434
- CALLED AS A FALLBACK_ when the relation has not already been loaded. This means that you should not
435
- apply any sorting or filtering to the relation queried in the resolve method. Instead used the
436
- `query` option described in the next section
437
-
438
- ```typescript
439
- builder.prismaObject('User', {
440
- findUnique: null,
441
- fields: (t) => ({
442
- id: t.exposeID('id'),
443
- posts: t.relation('posts', {
444
- resolve: (query, user) =>
445
- db.post.findMany({
446
- ...query,
447
- where: { authorId: user.id },
448
- }),
449
- }),
450
- }),
451
- });
452
- ```
453
-
454
409
  ### Filters, Sorting, and arguments
455
410
 
456
411
  So far we have been describing very simple queries without any arguments, filtering, or sorting. For
@@ -461,7 +416,6 @@ can either be a query object, or a method that returns a query object based on t
461
416
 
462
417
  ```typescript
463
418
  builder.prismaObject('User', {
464
- findUnique: (user) => ({ id: user.id }),
465
419
  fields: (t) => ({
466
420
  id: t.exposeID('id'),
467
421
  posts: t.relation('posts', {
@@ -486,12 +440,8 @@ passed into the first argument of the parent `t.prismaField`, and can include th
486
440
  the context for the current request. Because it is used for pre-loading data, and solving n+1
487
441
  issues, it can not be passed the `parent` object because it may not be loaded yet.
488
442
 
489
- If your field has a `resolve` method the generated `query` will be passed in as part of the first
490
- arg to your resolve function
491
-
492
443
  ```typescript
493
444
  builder.prismaObject('User', {
494
- findUnique: null,
495
445
  fields: (t) => ({
496
446
  id: t.exposeID('id'),
497
447
  email: t.exposeString('email'),
@@ -506,19 +456,11 @@ builder.prismaObject('User', {
506
456
  createdAt: args.oldestFirst ? 'asc' : 'desc',
507
457
  },
508
458
  }),
509
- // optional: query here will contain the orderBy (and any other properties returned by the query method)
510
- resolve: (query, post) => db.post.findMany({ ...query, where: { id: post.authorId } }),
511
459
  }),
512
460
  }),
513
461
  });
514
462
  ```
515
463
 
516
- It is _VERY IMPORTANT_ to put all your filtering and sorting into the query method rather than your
517
- resolver because the resolver is only used as fallback, and any filtering that does not exist in the
518
- query method will not be applied correctly. If you have a where in both your query and your
519
- resolver, you will need to ensure these are merged correctly. It is generally better NOT to use a
520
- custom resolver.
521
-
522
464
  ## relationCount
523
465
 
524
466
  Prisma supports querying for
@@ -528,7 +470,6 @@ support any filters on the counts, but can give a total count for a relation.
528
470
 
529
471
  ```typescript
530
472
  builder.prismaObject('User', {
531
- findUnique: (user) => ({ id: user.id }),
532
473
  fields: (t) => ({
533
474
  id: t.exposeID('id'),
534
475
  postCount: t.relationCount('posts'),
@@ -548,7 +489,6 @@ builder.prismaObject('User', {
548
489
  include: {
549
490
  profile: true,
550
491
  },
551
- findUnique: (user) => ({ id: user.id }),
552
492
  fields: (t) => ({
553
493
  id: t.exposeID('id'),
554
494
  email: t.exposeString('email'),
@@ -576,7 +516,6 @@ builder.prismaObject('User', {
576
516
  select: {
577
517
  id: true,
578
518
  },
579
- findUnique: (user) => ({ id: user.id }),
580
519
  fields: (t) => ({
581
520
  id: t.exposeID('id'),
582
521
  email: t.exposeString('email'),
@@ -584,7 +523,6 @@ builder.prismaObject('User', {
584
523
  });
585
524
  ```
586
525
 
587
- At the very least, you will need to `select` the properties required by your `findUnique` function.
588
526
  The `t.expose*` and `t.relation` methods will all automatically add selections for the exposed
589
527
  fields _WHEN THEY ARE QUERIED_, ensuring that only the requested columns will be loaded from the
590
528
  database.
@@ -596,7 +534,6 @@ builder.prismaObject('User', {
596
534
  select: {
597
535
  id: true,
598
536
  },
599
- findUnique: (user) => ({ id: user.id }),
600
537
  fields: (t) => ({
601
538
  id: t.exposeID('id'),
602
539
  email: t.exposeString('email'),
@@ -615,6 +552,155 @@ builder.prismaObject('User', {
615
552
  });
616
553
  ```
617
554
 
555
+ ## Using arguments or context in your selections
556
+
557
+ The following is a slightly contrived example, but shows how arguments can be used when creating a
558
+ selection for a field:
559
+
560
+ ```ts
561
+ const PostDraft = builder.prismaObject('Post', {
562
+ fields: (t) => ({
563
+ title: t.exposeString('title'),
564
+ commentFromDate: t.string({
565
+ args: {
566
+ date: t.arg({ type: 'Date', required: true }),
567
+ },
568
+ select: (args) => ({
569
+ comments: {
570
+ take: 1,
571
+ where: {
572
+ createdAt: {
573
+ gt: args.date,
574
+ },
575
+ },
576
+ },
577
+ }),
578
+ resolve: (post) => post.comments[0]?.content,
579
+ }),
580
+ }),
581
+ });
582
+ ```
583
+
584
+ ## Indirect relations (eg. Join tables)
585
+
586
+ If you want to define a GraphQL field that directly exposes data from a nested relationship (many to
587
+ many relations using a custom join table is a common example of this) you can use the
588
+ `nestedSelection` function passed to `select`.
589
+
590
+ Given a prisma schema like the following:
591
+
592
+ ```
593
+ model Post {
594
+ id Int @id @default(autoincrement())
595
+ title String
596
+ content String
597
+ media PostMedia[]
598
+ }
599
+
600
+ model Media {
601
+ id Int @id @default(autoincrement())
602
+ url String
603
+ posts PostMedia[]
604
+ uploadedBy User @relation(fields: [uploadedById], references: [id])
605
+ uploadedById Int
606
+ }
607
+
608
+ model PostMedia {
609
+ id Int @id @default(autoincrement())
610
+ post Post @relation(fields: [postId], references: [id])
611
+ media Media @relation(fields: [mediaId], references: [id])
612
+ postId Int
613
+ mediaId Int
614
+ }
615
+ ```
616
+
617
+ You can define a media field that can pre-load the correct relations based on the graphql query:
618
+
619
+ ```ts
620
+ const PostDraft = builder.prismaObject('Post', {
621
+ fields: (t) => ({
622
+ title: t.exposeString('title'),
623
+ media: t.field({
624
+ select: (args, ctx, nestedSelection) => ({
625
+ media: {
626
+ select: {
627
+ // This will look at what fields are queried on Media
628
+ // and automatically select uploadedBy if that relation is requested
629
+ media: nestedSelection(
630
+ // This arument is the default query for the media relation
631
+ // It could be something like: `{ select: { id: true } }` instead
632
+ true,
633
+ ),
634
+ },
635
+ },
636
+ }),
637
+ type: [Media],
638
+ resolve: (post) => post.media.map(({ media }) => media),
639
+ }),
640
+ }),
641
+ });
642
+
643
+ const Media = builder.prismaObject('Media', {
644
+ select: {
645
+ id: true,
646
+ },
647
+ fields: (t) => ({
648
+ url: t.exposeString('url'),
649
+ uploadedBy: t.relation('uploadedBy'),
650
+ }),
651
+ });
652
+ ```
653
+
654
+ ## Selecting fields from a nested GraphQL field
655
+
656
+ By default, the `nestedSelection` function will return selections based on the type of the current
657
+ field. `nestedSelection` can also be used to get a selection from a field nested deeper inside other
658
+ fields. This is useful if the field returns a type that is not a `prismaObject`, but a field nested
659
+ inside the returned type is.
660
+
661
+ ```ts
662
+ const PostRef = builder.prismaObject('Post', {
663
+ fields: (t) => ({
664
+ title: t.exposeString('title'),
665
+ content: t.exposeString('content'),
666
+ author: t.relation('author'),
667
+ }),
668
+ });
669
+
670
+ const PostPreview = builder.objectRef<Post>('PostPreview').implement({
671
+ fields: (t) => ({
672
+ post: t.field({
673
+ type: PostRef,
674
+ resolve: (post) => post,
675
+ }),
676
+ preview: t.string({
677
+ nullable: true,
678
+ resolve: (post) => post.content?.slice(10),
679
+ }),
680
+ }),
681
+ });
682
+
683
+ builder.prismaObject('User', {
684
+ fields: (t) => ({
685
+ id: t.exposeID('id'),
686
+ postPreviews: t.field({
687
+ select: (args, ctx, nestedSelection) => ({
688
+ posts: nestedSelection(
689
+ {
690
+ // limit the number of postPreviews to load
691
+ take: 2,
692
+ },
693
+ // Look at the selections in postPreviews.post to determine what relations/fields to select
694
+ ['post'],
695
+ ),
696
+ }),
697
+ type: [PostPreview],
698
+ resolve: (user) => user.posts,
699
+ }),
700
+ }),
701
+ });
702
+ ```
703
+
618
704
  ## Type variants
619
705
 
620
706
  The prisma plugin supports defining multiple GraphQL types based on the same prisma model.
@@ -625,7 +711,6 @@ described above). Additional variants can be defined by providing a `variant` op
625
711
  ```typescript
626
712
  const Viewer = builder.prismaObject('User', {
627
713
  variant: 'Viewer',
628
- findUnique: (user) => ({ id: user.id }),
629
714
  fields: (t) => ({
630
715
  id: t.exposeID('id'),
631
716
  });
@@ -636,7 +721,6 @@ You can define variant fields that reference one variant from another:
636
721
  ```typescript
637
722
  const Viewer = builder.prismaObject('User', {
638
723
  variant: 'Viewer',
639
- findUnique: (user) => ({ id: user.id }),
640
724
  fields: (t) => ({
641
725
  id: t.exposeID('id'),
642
726
  // Using the model name ('User') will reference the primary variant
@@ -653,7 +737,10 @@ const User = builder.prismaNode('User', {
653
737
  },
654
738
  fields: (t) => ({
655
739
  // To reference another variant, use the returned object Ref instead of the model name:
656
- viewer: t.variant(Viewer, {}),
740
+ viewer: t.variant(Viewer, {
741
+ // return null for viewer if the parent User is not the current user
742
+ isNull: (user, args, ctx) => user.id !== ctx.user.id,
743
+ }),
657
744
  email: t.exposeString('email'),
658
745
  }),
659
746
  });
@@ -664,10 +751,8 @@ You can also use variants when defining relations by providing a `type` option:
664
751
  ```typescript
665
752
  const PostDraft = builder.prismaNode('Post', {
666
753
  variant: 'PostDraft'
667
- // This is used to load the node by id
668
- findUnique: (id) => ({ id }),
669
- // This is used to get the id from a node
670
- id: { resolve: (post) => post.id },
754
+ // This set's what database field to use for the nodes id field
755
+ id: { field: 'id' },
671
756
  // fields work just like they do for builder.prismaObject
672
757
  fields: (t) => ({
673
758
  title: t.exposeString('title'),
@@ -677,7 +762,6 @@ const PostDraft = builder.prismaNode('Post', {
677
762
 
678
763
  const Viewer = builder.prismaObject('User', {
679
764
  variant: 'Viewer',
680
- findUnique: (user) => ({ id: user.id }),
681
765
  fields: (t) => ({
682
766
  id: t.exposeID('id'),
683
767
  drafts: t.relation('posts', {
@@ -700,17 +784,15 @@ connections very easy.
700
784
  The `prismaNode` method works just like the `prismaObject` method with a couple of small
701
785
  differences:
702
786
 
703
- - the `findUnique` function now only receives an id. This is to support relays ability to load nodes
704
- by id.
705
787
  - there is a new `id` option that mirrors the `id` option from `node` method of the relay plugin,
706
- and must contain a resolve function that returns the id from an instance of the node.
788
+ and must contain a resolve function that returns the id from an instance of the node. Rather than
789
+ defining a resolver for the id field, you can set the `field` option to the name of a unique
790
+ column or index.
707
791
 
708
792
  ```typescript
709
793
  builder.prismaNode('Post', {
710
- // This is used to load the node by id
711
- findUnique: (id) => ({ id }),
712
- // This is used to get the id from a node
713
- id: { resolve: (post) => post.id },
794
+ // This set's what database field to use for the nodes id field
795
+ id: { field: 'id' },
714
796
  // fields work just like they do for builder.prismaObject
715
797
  fields: (t) => ({
716
798
  title: t.exposeString('title'),
@@ -719,6 +801,21 @@ builder.prismaNode('Post', {
719
801
  });
720
802
  ```
721
803
 
804
+ If you need to customize how ids are formatted, you can add a resolver for the `id`, and provide a
805
+ `findUnique` option that can be used to load the node by it's id. This is generally not necissary.
806
+
807
+ ```typescript
808
+ builder.prismaNode('Post', {
809
+ id: { resolve: (post) => String(post.id) },
810
+ // The return value will be passed as the `where` of a `prisma.post.findUnique`
811
+ findUnique: (id) => ({ id: Number.parseInt(id, 10) }),
812
+ fields: (t) => ({
813
+ title: t.exposeString('title'),
814
+ author: t.relation('author'),
815
+ }),
816
+ });
817
+ ```
818
+
722
819
  ### `prismaConnection`
723
820
 
724
821
  The `prismaConnection` method on a field builder can be used to create a relay `connection` field
@@ -774,8 +871,7 @@ of the current model.
774
871
 
775
872
  ```typescript
776
873
  builder.prismaNode('User', {
777
- findUnique: (id) => ({ id }),
778
- id: { resolve: (user) => user.id },
874
+ id: { field: 'id' },
779
875
  fields: (t) => ({
780
876
  // Connections can be very simple to define
781
877
  simplePosts: t.relatedConnection('posts', {
@@ -810,11 +906,6 @@ builder.prismaNode('User', {
810
906
  - `maxSize`: (default: 100) The maximum number of nodes returned for a connection.
811
907
  - `query`: A method that accepts the `args` and `context` for the connection field, and returns
812
908
  filtering and sorting logic that will be merged into the query for the relation.
813
- - `resolve`: (optional) Used as a fallback when a connection is not pre-loaded. It is optional, and
814
- generally should NOT be defined manually. If used it works like a combination of the `resolve`
815
- method of `relation` and `prismaConnection`. The default will use the `findUnique` of the current
816
- model, with an `include` for the current relation. It is also batched together with other
817
- relationships to improve query efficiency.
818
909
  - `totalCount`: when set to true, this will add a `totalCount` field to the connection object. see
819
910
  `relationCount` above for more details.
820
911
 
@@ -946,5 +1037,5 @@ PostObject.implement({
946
1037
  With this setup, a parent resolver has the option to include the author, but we have a fallback
947
1038
  incase it does not.
948
1039
 
949
- There are other patterns like dataloaders than can be used to reduce n+1 issues, and make your graph
950
- more efficient, but they are too complex to describe here.
1040
+ There are other patterns like data loaders than can be used to reduce n+1 issues, and make your
1041
+ graph more efficient, but they are too complex to describe here.
@@ -38,10 +38,10 @@ declare global {
38
38
  select: Select;
39
39
  include: Include;
40
40
  }>>;
41
- prismaNode: 'relay' extends PluginName ? <Name extends keyof Types['PrismaTypes'], Interfaces extends InterfaceParam<Types>[] = [], Include = unknown, Select = unknown>(name: Name, options: PrismaNodeOptions<Types, Types['PrismaTypes'][Name] & PrismaModelTypes, Interfaces, Include, Select, ShapeFromSelection<PrismaModelTypes & Types['PrismaTypes'][Name], {
41
+ prismaNode: 'relay' extends PluginName ? <Name extends keyof Types['PrismaTypes'], Interfaces extends InterfaceParam<Types>[] = [], Include = unknown, Select = unknown, UniqueField = unknown>(name: Name, options: PrismaNodeOptions<Types, Types['PrismaTypes'][Name] & PrismaModelTypes, Interfaces, Include, Select, ShapeFromSelection<PrismaModelTypes & Types['PrismaTypes'][Name], {
42
42
  select: Select;
43
43
  include: Include;
44
- }>>) => PrismaNodeRef<Types['PrismaTypes'][Name] & PrismaModelTypes, ShapeFromSelection<PrismaModelTypes & Types['PrismaTypes'][Name], {
44
+ }>, UniqueField>) => PrismaNodeRef<Types['PrismaTypes'][Name] & PrismaModelTypes, ShapeFromSelection<PrismaModelTypes & Types['PrismaTypes'][Name], {
45
45
  select: Select;
46
46
  include: Include;
47
47
  }>> : '@pothos/plugin-relay is required to use this method';
@@ -1 +1 @@
1
- {"version":3,"file":"global-types.d.ts","sourceRoot":"","sources":["../src/global-types.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,aAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,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AAK,CAAC,GAC1C,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CA6C3D"}
@@ -1,4 +1,4 @@
1
- import { SchemaTypes } from '@pothos/core';
1
+ import { ObjectRef, SchemaTypes } from '@pothos/core';
2
2
  import { SelectionState } from './util/selections';
3
3
  export declare class ModelLoader {
4
4
  model: object;
@@ -10,7 +10,18 @@ export declare class ModelLoader {
10
10
  state: SelectionState;
11
11
  }>;
12
12
  constructor(model: object, builder: PothosSchemaTypes.SchemaBuilder<never>, modelName: string, findUnique: (args: unknown, ctx: {}) => unknown);
13
- static forRef<Types extends SchemaTypes>(modelName: string, findUnique: (args: unknown, ctx: {}) => unknown, builder: PothosSchemaTypes.SchemaBuilder<Types>): import("@pothos/core").ContextCache<ModelLoader, object, []>;
13
+ static forRef<Types extends SchemaTypes>(ref: ObjectRef<unknown>, modelName: string, findUnique: (args: unknown, ctx: {}) => unknown, builder: PothosSchemaTypes.SchemaBuilder<Types>): import("@pothos/core").ContextCache<ModelLoader, object, []>;
14
+ static getFindUnique(findBy: {
15
+ name: string | null;
16
+ fields: string[];
17
+ } | string): (model: Record<string, unknown>) => {};
18
+ static getDefaultFindBy<Types extends SchemaTypes>(ref: ObjectRef<unknown>, modelName: string, builder: PothosSchemaTypes.SchemaBuilder<Types>): string | {
19
+ name: string | null;
20
+ fields: string[];
21
+ };
22
+ static getDefaultFindUnique<Types extends SchemaTypes>(ref: ObjectRef<unknown>, modelName: string, builder: PothosSchemaTypes.SchemaBuilder<Types>): (model: Record<string, unknown>) => {};
23
+ static getDefaultIDSelection<Types extends SchemaTypes>(ref: ObjectRef<unknown>, modelName: string, builder: PothosSchemaTypes.SchemaBuilder<Types>): Record<string, boolean>;
24
+ static getFindUniqueForField<Types extends SchemaTypes>(ref: ObjectRef<unknown>, modelName: string, fieldName: string, builder: PothosSchemaTypes.SchemaBuilder<Types>): (model: Record<string, unknown>) => {};
14
25
  loadSelection(selection: SelectionState, context: object): Promise<Record<string, unknown>>;
15
26
  initLoad(state: SelectionState, context: {}): Promise<Record<string, unknown>>;
16
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/D,OAAO,EAGL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,WAAW;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChD,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO,CAAC;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,MAAM;iBACK,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;eAClC,cAAc;OAClB;gBAGH,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC,EAC/C,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO;IAQjD,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,WAAW,EACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,OAAO,EAC/C,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC;IAO3C,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM;IAcxD,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE;CAuBlD"}
1
+ {"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;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SAAQ,eAAe,CAC3F,KAAK,EACL,CAAC,CACF;IACC,CAAC,sBAAsB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAEvC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EACxB,KAAK,EAAE,CAAC,GACP,CAAC,SAAS,CAAC,EAAE,GAAG;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IAYrE,QAAQ,CAAC,KAAK,EAAE,OAAO;CAQxB"}
1
+ {"version":3,"file":"node-ref.d.ts","sourceRoot":"","sources":["../src/node-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAA+B,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,aAAa,CAAC,KAAK,SAAS,gBAAgB,EAAE,CAAC,CAAE,SAAQ,eAAe,CAC3F,KAAK,EACL,CAAC,CACF;IACC,CAAC,sBAAsB,CAAC,EAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAExC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EACxB,KAAK,EAAE,CAAC,GACP,CAAC,SAAS,CAAC,EAAE,GAAG;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IAYrE,QAAQ,CAAC,KAAK,EAAE,OAAO;CAQxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"object-ref.d.ts","sourceRoot":"","sources":["../src/object-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAErC,eAAO,MAAM,cAAc,eAAsC,CAAC;AAElE,qBAAa,eAAe,CAAC,KAAK,SAAS,gBAAgB,EAAE,CAAC,GAAG,EAAE,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACvF,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC;CACzB"}
1
+ {"version":3,"file":"object-ref.d.ts","sourceRoot":"","sources":["../src/object-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAErC,eAAO,MAAM,cAAc,eAAsC,CAAC;AAElE,qBAAa,eAAe,CAAC,KAAK,SAAS,gBAAgB,EAAE,CAAC,GAAG,EAAE,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACvF,CAAC,cAAc,CAAC,EAAG,KAAK,CAAC;CAC1B"}