@nestledjs/api 2.0.0 → 2.0.1
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/package.json
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import graphqlFields from 'graphql-fields'
|
|
2
|
-
import { Prisma } from '@<%= npmScope %>/api/prisma'
|
|
3
|
-
import type { DMMF } from '@prisma/client/runtime/library'
|
|
4
2
|
import { GraphQLResolveInfo } from 'graphql/type'
|
|
5
|
-
|
|
6
|
-
const dmmf = Prisma.dmmf
|
|
3
|
+
import { DATABASE_MODELS, DatabaseModel, DatabaseField } from '@<%= npmScope %>/shared/sdk'
|
|
7
4
|
|
|
8
5
|
function getNamedType(type: any): string {
|
|
9
6
|
if (type.ofType) return getNamedType(type.ofType)
|
|
10
7
|
return type.name
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
function getModelFromTypeName(typeName: string) {
|
|
14
|
-
return
|
|
10
|
+
function getModelFromTypeName(typeName: string): DatabaseModel | undefined {
|
|
11
|
+
return DATABASE_MODELS.find(m => m.name === typeName)
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
function buildSelectTree(fieldTree: any, model:
|
|
14
|
+
function buildSelectTree(fieldTree: any, model: DatabaseModel): any {
|
|
18
15
|
const result: Record<string, any> = {}
|
|
19
16
|
|
|
20
17
|
for (const key in fieldTree) {
|
|
21
|
-
const field = model.fields.find((f:
|
|
18
|
+
const field = model.fields.find((f: DatabaseField) => f.name === key)
|
|
22
19
|
if (!field) continue
|
|
23
20
|
|
|
24
21
|
if (field.relationName && typeof fieldTree[key] === 'object') {
|
|
25
|
-
const relatedModel =
|
|
22
|
+
const relatedModel = DATABASE_MODELS.find(m => m.name === field.type)
|
|
26
23
|
if (relatedModel) {
|
|
27
24
|
result[key] = {
|
|
28
25
|
select: buildSelectTree(fieldTree[key], relatedModel),
|
|
@@ -38,13 +35,14 @@ function buildSelectTree(fieldTree: any, model: any): any {
|
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
37
|
* Automatically converts a GraphQL `info` object into a Prisma `select` object.
|
|
38
|
+
* Uses the generated DATABASE_MODELS for schema introspection (Prisma v7 compatible).
|
|
41
39
|
*/
|
|
42
40
|
export function createSelect(info: GraphQLResolveInfo) {
|
|
43
41
|
const returnTypeName = getNamedType(info.returnType)
|
|
44
42
|
const model = getModelFromTypeName(returnTypeName)
|
|
45
43
|
|
|
46
44
|
if (!model) {
|
|
47
|
-
throw new Error(`Model "${returnTypeName}" not found in
|
|
45
|
+
throw new Error(`Model "${returnTypeName}" not found in DATABASE_MODELS. Make sure to run the SDK generator.`)
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
const rawFields = graphqlFields(info)
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Export all types and client from Prisma v7 generated files
|
|
2
|
+
export * from './lib/prisma-generated/client'
|
|
3
|
+
|
|
4
|
+
// Explicitly export Prisma namespace for better CI compatibility
|
|
5
|
+
export { Prisma } from './lib/prisma-generated/client'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config'
|
|
2
|
-
import { PrismaClient } from '../prisma-generated'
|
|
2
|
+
import { PrismaClient } from '../prisma-generated/client'
|
|
3
3
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
4
4
|
import { countries } from './seed-data/iso-3166-countries'
|
|
5
5
|
import { seedUsers } from './seed-data/seed-users'
|