-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prisma): make resolvers testable with PrismaSelectService
undefined
- Loading branch information
1 parent
01e8f4c
commit 1300ddd
Showing
6 changed files
with
56 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './default-fields'; | ||
export * from './generated'; | ||
export * from './prisma-select-args'; | ||
export * from './prisma-select.service'; | ||
export * from './prisma.module'; | ||
export * from './prisma.service'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaSelect } from '@paljs/plugins'; | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
|
||
import { PalDefaultFields } from './default-fields'; | ||
import { Prisma } from './generated'; | ||
|
||
@Injectable() | ||
export class PrismaSelectService { | ||
getArgs(info: GraphQLResolveInfo, args: object, defaultFields?: PalDefaultFields) { | ||
const result = new PrismaSelect(info, { | ||
defaultFields: defaultFields as any, | ||
dmmf: [Prisma.dmmf], | ||
}).value; | ||
|
||
if (!result.select || Object.keys(result.select).length > 0) { | ||
return { | ||
...args, | ||
...result, | ||
}; | ||
} | ||
|
||
return args; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { PrismaSelectService } from './prisma-select.service'; | ||
import { PrismaService } from './prisma.service'; | ||
|
||
@Module({ | ||
providers: [PrismaService], | ||
exports: [PrismaService], | ||
providers: [PrismaService, PrismaSelectService], | ||
exports: [PrismaService, PrismaSelectService], | ||
}) | ||
export class PrismaModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters