Skip to content

Commit

Permalink
feat: install graphql-list-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Mar 29, 2024
1 parent 5c33eb5 commit c5d367b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
28 changes: 28 additions & 0 deletions luna-backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions luna-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"compression": "^1.7.4",
"fs-jetpack": "^5.1.0",
"graphql": "^16.8.1",
"graphql-list-fields": "^2.0.4",
"helmet": "^7.0.0",
"inclusion": "^1.0.1",
"jsonwebtoken": "^9.0.2",
Expand All @@ -69,6 +70,7 @@
"@nestjs/testing": "^10.0.0",
"@types/compression": "^1.7.4",
"@types/express": "^4.17.17",
"@types/graphql-list-fields": "^2.0.6",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.14.202",
"@types/multer": "^1.4.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Resolver } from '@nestjs/graphql';
import { Info, Resolver } from '@nestjs/graphql';
import { GraphQLResolveInfo } from 'graphql';
import getFieldNames from 'graphql-list-fields';
import * as Dto from '../../(spec)';
import { IContextoDeAcesso } from '../../../../domain';
import { ContextoDeAcessoGraphQl, DtoOperationGqlMutation, DtoOperationGqlQuery } from '../../../../infrastructure';
Expand All @@ -16,8 +18,9 @@ export class BlocoResolver {
//

@DtoOperationGqlQuery(BlocoOperations.BLOCO_FIND_ALL)
async blocoFindAll(@ContextoDeAcessoGraphQl() contextoDeAcesso: IContextoDeAcesso, @GqlDtoInput(BlocoOperations.BLOCO_FIND_ALL) dto: Dto.ISearchInputDto) {
return this.blocoService.blocoFindAll(contextoDeAcesso, dto);
async blocoFindAll(@ContextoDeAcessoGraphQl() contextoDeAcesso: IContextoDeAcesso, @GqlDtoInput(BlocoOperations.BLOCO_FIND_ALL) dto: Dto.ISearchInputDto, @Info() info: GraphQLResolveInfo) {
const fields = getFieldNames(<any>info);
return this.blocoService.blocoFindAll(contextoDeAcesso, dto, fields);
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BlocoService {

//

async blocoFindAll(contextoDeAcesso: IContextoDeAcesso, dto?: Dtos.ISearchInputDto): Promise<Dtos.IBlocoFindAllResultDto> {
async blocoFindAll(contextoDeAcesso: IContextoDeAcesso, dto?: Dtos.ISearchInputDto, fields: string[] | null = null): Promise<Dtos.IBlocoFindAllResultDto> {
// =========================================================

const qb = this.blocoRepository.createQueryBuilder(aliasBloco);
Expand All @@ -74,6 +74,14 @@ export class BlocoService {

await contextoDeAcesso.aplicarFiltro('bloco:find', qb, aliasBloco, null);

console.log(JSON.stringify({ fields }, null, 2));

if (fields) {
if (fields.find((i) => i.startsWith('data.imagemCapa.imagemArquivo.arquivo'))) {
console.log('aa');
}
}

// =========================================================

const paginated = await paginate(getPaginateQueryFromSearchInput(dto), qb.clone(), {
Expand Down

0 comments on commit c5d367b

Please sign in to comment.