@pothos/plugin-prisma 3.8.0 → 3.11.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.
- package/CHANGELOG.md +22 -0
- package/README.md +187 -94
- package/dts/global-types.d.ts +2 -2
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/model-loader.d.ts +13 -2
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +5 -5
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +16 -8
- package/dts/types.d.ts.map +1 -1
- package/dts/util/cursors.d.ts +5 -1
- package/dts/util/cursors.d.ts.map +1 -1
- package/dts/util/datamodel.d.ts +5 -1
- package/dts/util/datamodel.d.ts.map +1 -1
- package/dts/util/get-client.d.ts +5 -1
- package/dts/util/get-client.d.ts.map +1 -1
- package/dts/util/loader-map.d.ts +2 -2
- package/dts/util/loader-map.d.ts.map +1 -1
- package/dts/util/map-query.d.ts.map +1 -1
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.js +5 -7
- package/esm/index.js.map +1 -1
- package/esm/model-loader.js +88 -3
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.js.map +1 -1
- package/esm/prisma-field-builder.js +16 -21
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +24 -16
- package/esm/schema-builder.js.map +1 -1
- package/esm/util/cursors.js +95 -2
- package/esm/util/cursors.js.map +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/get-client.js.map +1 -1
- package/esm/util/loader-map.js +2 -3
- package/esm/util/loader-map.js.map +1 -1
- package/esm/util/map-query.js +47 -9
- package/esm/util/map-query.js.map +1 -1
- package/esm/util/relation-map.js.map +1 -1
- package/esm/util/selections.js.map +1 -1
- package/lib/field-builder.js +3 -6
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +8 -16
- package/lib/generator.js.map +1 -1
- package/lib/index.js +6 -21
- package/lib/index.js.map +1 -1
- package/lib/model-loader.js +82 -3
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.js +1 -2
- package/lib/node-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +25 -40
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +25 -19
- package/lib/schema-builder.js.map +1 -1
- package/lib/util/cursors.js +100 -6
- package/lib/util/cursors.js.map +1 -1
- package/lib/util/datamodel.js +2 -4
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/get-client.js +1 -3
- package/lib/util/get-client.js.map +1 -1
- package/lib/util/loader-map.js +3 -5
- package/lib/util/loader-map.js.map +1 -1
- package/lib/util/map-query.js +47 -9
- package/lib/util/map-query.js.map +1 -1
- package/lib/util/relation-map.js +1 -2
- package/lib/util/relation-map.js.map +1 -1
- package/lib/util/selections.js +2 -4
- package/lib/util/selections.js.map +1 -1
- package/package.json +8 -8
- package/src/global-types.ts +3 -1
- package/src/index.ts +14 -4
- package/src/model-loader.ts +144 -3
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +1 -1
- package/src/prisma-field-builder.ts +21 -22
- package/src/schema-builder.ts +25 -20
- package/src/types.ts +32 -8
- package/src/util/cursors.ts +117 -1
- package/src/util/get-client.ts +2 -1
- package/src/util/loader-map.ts +3 -9
- package/src/util/map-query.ts +66 -3
- package/tsconfig.type.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 79e69c2b: Add resolveCursorConnection helper for relay plugin
|
|
8
|
+
|
|
9
|
+
## 3.10.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 384b0fb6: Make findUnique optional by defaulting to id/unique fields defined in prisma schema
|
|
14
|
+
|
|
15
|
+
## 3.9.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- e090a835: Add fieldWithSelection method to support indirect relions
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 4e5756ca: Update dev dependencies
|
|
24
|
+
|
|
3
25
|
## 3.8.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
|
-
|
|
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.
|
|
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
|
|
|
@@ -263,7 +257,6 @@ const builder = new SchemaBuilder<{
|
|
|
263
257
|
builder.prismaObject('User', {
|
|
264
258
|
// Optional name for the object, defaults to the name of the prisma model
|
|
265
259
|
name: 'PostAuthor',
|
|
266
|
-
findUnique: (user) => ({ id: user.id }),
|
|
267
260
|
fields: (t) => ({
|
|
268
261
|
id: t.exposeID('id'),
|
|
269
262
|
email: t.exposeString('email'),
|
|
@@ -271,7 +264,6 @@ builder.prismaObject('User', {
|
|
|
271
264
|
});
|
|
272
265
|
|
|
273
266
|
builder.prismaObject('Post', {
|
|
274
|
-
findUnique: (post) => ({ id: post.id }),
|
|
275
267
|
fields: (t) => ({
|
|
276
268
|
id: t.exposeID('id'),
|
|
277
269
|
title: t.exposeString('title'),
|
|
@@ -283,8 +275,6 @@ So far, this is just creating some simple object types. They work just like any
|
|
|
283
275
|
Pothos. The main advantage of this is that we get the type information without using object refs, or
|
|
284
276
|
needing imports from prisma client.
|
|
285
277
|
|
|
286
|
-
The `findUnique` option is described more below.
|
|
287
|
-
|
|
288
278
|
## Adding prisma fields to non-prisma objects (including Query and Mutation)
|
|
289
279
|
|
|
290
280
|
There is a new `t.prismaField` method which can be used to define fields that resolve to your prisma
|
|
@@ -341,7 +331,6 @@ builder.queryType({
|
|
|
341
331
|
});
|
|
342
332
|
|
|
343
333
|
builder.prismaObject('User', {
|
|
344
|
-
findUnique: (user) => ({ id: user.id }),
|
|
345
334
|
fields: (t) => ({
|
|
346
335
|
id: t.exposeID('id'),
|
|
347
336
|
email: t.exposeString('email'),
|
|
@@ -350,7 +339,6 @@ builder.prismaObject('User', {
|
|
|
350
339
|
});
|
|
351
340
|
|
|
352
341
|
builder.prismaObject('Post', {
|
|
353
|
-
findUnique: (post) => ({ id: post.id }),
|
|
354
342
|
fields: (t) => ({
|
|
355
343
|
id: t.exposeID('id'),
|
|
356
344
|
title: t.exposeString('title'),
|
|
@@ -393,26 +381,24 @@ the `me` `prismaField` would receive something like the following as its query p
|
|
|
393
381
|
```
|
|
394
382
|
|
|
395
383
|
This will work perfectly for the majority of queries. There are a number of edge cases that make it
|
|
396
|
-
impossible to resolve everything in a single query. When this happens
|
|
397
|
-
|
|
398
|
-
possible.
|
|
399
|
-
|
|
400
|
-
### Find Unique
|
|
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
|
|
401
387
|
|
|
402
|
-
|
|
403
|
-
and should return an object that will be passed as a `where` in a `prisma.findUnique`. Generally,
|
|
404
|
-
this will just be something like: `user => { id: user.id }` where `id` is the primary key for the
|
|
405
|
-
table.
|
|
388
|
+
### Fallback queryies
|
|
406
389
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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.
|
|
410
395
|
|
|
411
396
|
The following are some edge cases that could cause an additional query to be necessary:
|
|
412
397
|
|
|
413
398
|
- The parent object was not loaded through a field defined with `t.prismaField`, or `t.relation`
|
|
414
399
|
- The root `prismaField` did not correctly spread the `query` arguments in is prisma call.
|
|
415
|
-
- The query selects multiple fields that use the same relation with different
|
|
400
|
+
- The query selects multiple fields that use the same relation with different filters, sorting, or
|
|
401
|
+
limits
|
|
416
402
|
- The query contains multiple aliases for the same relation field with different arguments in a way
|
|
417
403
|
that results in different query options for the relation.
|
|
418
404
|
- A relation field has a query that is incompatible with the default includes of the parent object
|
|
@@ -420,32 +406,6 @@ The following are some edge cases that could cause an additional query to be nec
|
|
|
420
406
|
All of the above should be relatively uncommon in normal usage, but the plugin ensures that these
|
|
421
407
|
types of edge cases are automatically handled when they do occur.
|
|
422
408
|
|
|
423
|
-
### Without Find Unique
|
|
424
|
-
|
|
425
|
-
This is generally _NOT RECOMMENDED_, but you can set `findUnique` to null for some prisma objects.
|
|
426
|
-
Doing this will prevent the plugin from resolving queries for conflicting relations. Because of
|
|
427
|
-
this, you will need to provide a `resolve` method when defining relations, and some other options
|
|
428
|
-
(like field level selects, described below) will not be available. This `resolve` method is _ONLY
|
|
429
|
-
CALLED AS A FALLBACK_ when the relation has not already been loaded. This means that you should not
|
|
430
|
-
apply any sorting or filtering to the relation queried in the resolve method. Instead used the
|
|
431
|
-
`query` option described in the next section
|
|
432
|
-
|
|
433
|
-
```typescript
|
|
434
|
-
builder.prismaObject('User', {
|
|
435
|
-
findUnique: null,
|
|
436
|
-
fields: (t) => ({
|
|
437
|
-
id: t.exposeID('id'),
|
|
438
|
-
posts: t.relation('posts', {
|
|
439
|
-
resolve: (query, user) =>
|
|
440
|
-
db.post.findMany({
|
|
441
|
-
...query,
|
|
442
|
-
where: { authorId: user.id },
|
|
443
|
-
}),
|
|
444
|
-
}),
|
|
445
|
-
}),
|
|
446
|
-
});
|
|
447
|
-
```
|
|
448
|
-
|
|
449
409
|
### Filters, Sorting, and arguments
|
|
450
410
|
|
|
451
411
|
So far we have been describing very simple queries without any arguments, filtering, or sorting. For
|
|
@@ -456,7 +416,6 @@ can either be a query object, or a method that returns a query object based on t
|
|
|
456
416
|
|
|
457
417
|
```typescript
|
|
458
418
|
builder.prismaObject('User', {
|
|
459
|
-
findUnique: (user) => ({ id: user.id }),
|
|
460
419
|
fields: (t) => ({
|
|
461
420
|
id: t.exposeID('id'),
|
|
462
421
|
posts: t.relation('posts', {
|
|
@@ -481,12 +440,8 @@ passed into the first argument of the parent `t.prismaField`, and can include th
|
|
|
481
440
|
the context for the current request. Because it is used for pre-loading data, and solving n+1
|
|
482
441
|
issues, it can not be passed the `parent` object because it may not be loaded yet.
|
|
483
442
|
|
|
484
|
-
If your field has a `resolve` method the generated `query` will be passed in as part of the first
|
|
485
|
-
arg to your resolve function
|
|
486
|
-
|
|
487
443
|
```typescript
|
|
488
444
|
builder.prismaObject('User', {
|
|
489
|
-
findUnique: null,
|
|
490
445
|
fields: (t) => ({
|
|
491
446
|
id: t.exposeID('id'),
|
|
492
447
|
email: t.exposeString('email'),
|
|
@@ -501,19 +456,11 @@ builder.prismaObject('User', {
|
|
|
501
456
|
createdAt: args.oldestFirst ? 'asc' : 'desc',
|
|
502
457
|
},
|
|
503
458
|
}),
|
|
504
|
-
// optional: query here will contain the orderBy (and any other properties returned by the query method)
|
|
505
|
-
resolve: (query, post) => db.post.findMany({ ...query, where: { id: post.authorId } }),
|
|
506
459
|
}),
|
|
507
460
|
}),
|
|
508
461
|
});
|
|
509
462
|
```
|
|
510
463
|
|
|
511
|
-
It is _VERY IMPORTANT_ to put all your filtering and sorting into the query method rather than your
|
|
512
|
-
resolver because the resolver is only used as fallback, and any filtering that does not exist in the
|
|
513
|
-
query method will not be applied correctly. If you have a where in both your query and your
|
|
514
|
-
resolver, you will need to ensure these are merged correctly. It is generally better NOT to use a
|
|
515
|
-
custom resolver.
|
|
516
|
-
|
|
517
464
|
## relationCount
|
|
518
465
|
|
|
519
466
|
Prisma supports querying for
|
|
@@ -523,7 +470,6 @@ support any filters on the counts, but can give a total count for a relation.
|
|
|
523
470
|
|
|
524
471
|
```typescript
|
|
525
472
|
builder.prismaObject('User', {
|
|
526
|
-
findUnique: (user) => ({ id: user.id }),
|
|
527
473
|
fields: (t) => ({
|
|
528
474
|
id: t.exposeID('id'),
|
|
529
475
|
postCount: t.relationCount('posts'),
|
|
@@ -543,7 +489,6 @@ builder.prismaObject('User', {
|
|
|
543
489
|
include: {
|
|
544
490
|
profile: true,
|
|
545
491
|
},
|
|
546
|
-
findUnique: (user) => ({ id: user.id }),
|
|
547
492
|
fields: (t) => ({
|
|
548
493
|
id: t.exposeID('id'),
|
|
549
494
|
email: t.exposeString('email'),
|
|
@@ -571,7 +516,6 @@ builder.prismaObject('User', {
|
|
|
571
516
|
select: {
|
|
572
517
|
id: true,
|
|
573
518
|
},
|
|
574
|
-
findUnique: (user) => ({ id: user.id }),
|
|
575
519
|
fields: (t) => ({
|
|
576
520
|
id: t.exposeID('id'),
|
|
577
521
|
email: t.exposeString('email'),
|
|
@@ -579,7 +523,6 @@ builder.prismaObject('User', {
|
|
|
579
523
|
});
|
|
580
524
|
```
|
|
581
525
|
|
|
582
|
-
At the very least, you will need to `select` the properties required by your `findUnique` function.
|
|
583
526
|
The `t.expose*` and `t.relation` methods will all automatically add selections for the exposed
|
|
584
527
|
fields _WHEN THEY ARE QUERIED_, ensuring that only the requested columns will be loaded from the
|
|
585
528
|
database.
|
|
@@ -591,7 +534,6 @@ builder.prismaObject('User', {
|
|
|
591
534
|
select: {
|
|
592
535
|
id: true,
|
|
593
536
|
},
|
|
594
|
-
findUnique: (user) => ({ id: user.id }),
|
|
595
537
|
fields: (t) => ({
|
|
596
538
|
id: t.exposeID('id'),
|
|
597
539
|
email: t.exposeString('email'),
|
|
@@ -610,6 +552,155 @@ builder.prismaObject('User', {
|
|
|
610
552
|
});
|
|
611
553
|
```
|
|
612
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
|
+
|
|
613
704
|
## Type variants
|
|
614
705
|
|
|
615
706
|
The prisma plugin supports defining multiple GraphQL types based on the same prisma model.
|
|
@@ -620,7 +711,6 @@ described above). Additional variants can be defined by providing a `variant` op
|
|
|
620
711
|
```typescript
|
|
621
712
|
const Viewer = builder.prismaObject('User', {
|
|
622
713
|
variant: 'Viewer',
|
|
623
|
-
findUnique: (user) => ({ id: user.id }),
|
|
624
714
|
fields: (t) => ({
|
|
625
715
|
id: t.exposeID('id'),
|
|
626
716
|
});
|
|
@@ -631,7 +721,6 @@ You can define variant fields that reference one variant from another:
|
|
|
631
721
|
```typescript
|
|
632
722
|
const Viewer = builder.prismaObject('User', {
|
|
633
723
|
variant: 'Viewer',
|
|
634
|
-
findUnique: (user) => ({ id: user.id }),
|
|
635
724
|
fields: (t) => ({
|
|
636
725
|
id: t.exposeID('id'),
|
|
637
726
|
// Using the model name ('User') will reference the primary variant
|
|
@@ -662,10 +751,8 @@ You can also use variants when defining relations by providing a `type` option:
|
|
|
662
751
|
```typescript
|
|
663
752
|
const PostDraft = builder.prismaNode('Post', {
|
|
664
753
|
variant: 'PostDraft'
|
|
665
|
-
// This
|
|
666
|
-
|
|
667
|
-
// This is used to get the id from a node
|
|
668
|
-
id: { resolve: (post) => post.id },
|
|
754
|
+
// This set's what database field to use for the nodes id field
|
|
755
|
+
id: { field: 'id' },
|
|
669
756
|
// fields work just like they do for builder.prismaObject
|
|
670
757
|
fields: (t) => ({
|
|
671
758
|
title: t.exposeString('title'),
|
|
@@ -675,7 +762,6 @@ const PostDraft = builder.prismaNode('Post', {
|
|
|
675
762
|
|
|
676
763
|
const Viewer = builder.prismaObject('User', {
|
|
677
764
|
variant: 'Viewer',
|
|
678
|
-
findUnique: (user) => ({ id: user.id }),
|
|
679
765
|
fields: (t) => ({
|
|
680
766
|
id: t.exposeID('id'),
|
|
681
767
|
drafts: t.relation('posts', {
|
|
@@ -698,17 +784,15 @@ connections very easy.
|
|
|
698
784
|
The `prismaNode` method works just like the `prismaObject` method with a couple of small
|
|
699
785
|
differences:
|
|
700
786
|
|
|
701
|
-
- the `findUnique` function now only receives an id. This is to support relays ability to load nodes
|
|
702
|
-
by id.
|
|
703
787
|
- there is a new `id` option that mirrors the `id` option from `node` method of the relay plugin,
|
|
704
|
-
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.
|
|
705
791
|
|
|
706
792
|
```typescript
|
|
707
793
|
builder.prismaNode('Post', {
|
|
708
|
-
// This
|
|
709
|
-
|
|
710
|
-
// This is used to get the id from a node
|
|
711
|
-
id: { resolve: (post) => post.id },
|
|
794
|
+
// This set's what database field to use for the nodes id field
|
|
795
|
+
id: { field: 'id' },
|
|
712
796
|
// fields work just like they do for builder.prismaObject
|
|
713
797
|
fields: (t) => ({
|
|
714
798
|
title: t.exposeString('title'),
|
|
@@ -717,6 +801,21 @@ builder.prismaNode('Post', {
|
|
|
717
801
|
});
|
|
718
802
|
```
|
|
719
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
|
+
|
|
720
819
|
### `prismaConnection`
|
|
721
820
|
|
|
722
821
|
The `prismaConnection` method on a field builder can be used to create a relay `connection` field
|
|
@@ -772,8 +871,7 @@ of the current model.
|
|
|
772
871
|
|
|
773
872
|
```typescript
|
|
774
873
|
builder.prismaNode('User', {
|
|
775
|
-
|
|
776
|
-
id: { resolve: (user) => user.id },
|
|
874
|
+
id: { field: 'id' },
|
|
777
875
|
fields: (t) => ({
|
|
778
876
|
// Connections can be very simple to define
|
|
779
877
|
simplePosts: t.relatedConnection('posts', {
|
|
@@ -808,11 +906,6 @@ builder.prismaNode('User', {
|
|
|
808
906
|
- `maxSize`: (default: 100) The maximum number of nodes returned for a connection.
|
|
809
907
|
- `query`: A method that accepts the `args` and `context` for the connection field, and returns
|
|
810
908
|
filtering and sorting logic that will be merged into the query for the relation.
|
|
811
|
-
- `resolve`: (optional) Used as a fallback when a connection is not pre-loaded. It is optional, and
|
|
812
|
-
generally should NOT be defined manually. If used it works like a combination of the `resolve`
|
|
813
|
-
method of `relation` and `prismaConnection`. The default will use the `findUnique` of the current
|
|
814
|
-
model, with an `include` for the current relation. It is also batched together with other
|
|
815
|
-
relationships to improve query efficiency.
|
|
816
909
|
- `totalCount`: when set to true, this will add a `totalCount` field to the connection object. see
|
|
817
910
|
`relationCount` above for more details.
|
|
818
911
|
|
|
@@ -944,5 +1037,5 @@ PostObject.implement({
|
|
|
944
1037
|
With this setup, a parent resolver has the option to include the author, but we have a fallback
|
|
945
1038
|
incase it does not.
|
|
946
1039
|
|
|
947
|
-
There are other patterns like
|
|
948
|
-
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.
|
package/dts/global-types.d.ts
CHANGED
|
@@ -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
|
-
}
|
|
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/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AAI,SAAS,UAAU,CAAC,KAAK,CAAC,EAC9B,QAAQ,SAAS,OAAO,EACxB,eAAe,SAAS,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,EACnD,eAAe,SAAS,OAAO,EAC/B,IAAI,SAAS,aAAa,EAC1B,kBAAkB;SAChB;QAEJ,UAAiB,uBAAuB,CACtC,KAAK,SAAS,WAAW,EACzB,IAAI,SAAS,UAAU,CAAC,KAAK,CAAC,EAC9B,eAAe,SAAS,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,EACnD,eAAe,SAAS,OAAO,EAC/B,QAAQ;SACN;QAEJ,UAAiB,2BAA2B,CAC1C,KAAK,SAAS,WAAW,EACzB,IAAI,SAAS,UAAU,CAAC,KAAK,CAAC,EAC9B,eAAe,SAAS,OAAO,EAC/B,QAAQ;SACN;QAEJ,UAAiB,0BAA0B;YACzC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;YAClC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;YACjC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;YACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;SACnC;QAED,UAAiB,qBAAqB,CAAC,KAAK,SAAS,WAAW,EAAE,CAAC,EAAE,QAAQ;SAAI;KAClF;CACF"}
|
package/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AACxB,OAAO,iBAAiB,CAAC;AACzB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AACxB,OAAO,iBAAiB,CAAC;AACzB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAsB,EACpB,UAAU,EACV,UAAU,EACV,uBAAuB,EACvB,WAAW,EACZ,MAAM,cAAc,CAAC;AAKtB,cAAc,SAAS,CAAC;AAExB,QAAA,MAAM,UAAU,UAAoB,CAAC;AAErC,eAAe,UAAU,CAAC;AAE1B,qBAAa,YAAY,CAAC,KAAK,SAAS,WAAW,CAAE,SAAQ,UAAU,CAAC,KAAK,CAAC;gBAChE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC;IAI3B,mBAAmB,CAC1B,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,GAC1C,uBAAuB,CAAC,KAAK,CAAC,GAAG,IAAI;IA4B/B,WAAW,CAClB,QAAQ,EAAE,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAC1E,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,GAC1C,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CA6C3D"}
|
package/dts/model-loader.d.ts
CHANGED
|
@@ -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;
|
|
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;AAG1E,OAAO,EAGL,cAAc,EAEf,MAAM,mBAAmB,C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Q,eAAe,CAC3F,KAAK,EACL,CAAC,CACF;IACC,CAAC,sBAAsB,CAAC,
|
|
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"}
|
package/dts/object-ref.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|