From c5d367bd112dff9926ebdc858144cb42410bca7d Mon Sep 17 00:00:00 2001 From: "Gabriel R. Antunes" Date: Fri, 29 Mar 2024 08:07:39 -0400 Subject: [PATCH] feat: install graphql-list-fields --- luna-backend/package-lock.json | 28 +++++++++++++++++++ luna-backend/package.json | 2 ++ .../ambientes/bloco/bloco.resolver.ts | 9 ++++-- .../business/ambientes/bloco/bloco.service.ts | 10 ++++++- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/luna-backend/package-lock.json b/luna-backend/package-lock.json index a11b2407..a1b033c5 100644 --- a/luna-backend/package-lock.json +++ b/luna-backend/package-lock.json @@ -24,6 +24,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", @@ -50,6 +51,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", @@ -3805,6 +3807,27 @@ "@types/node": "*" } }, + "node_modules/@types/graphql-list-fields": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/graphql-list-fields/-/graphql-list-fields-2.0.6.tgz", + "integrity": "sha512-X+pNudS8ZwEz6QCC01IU3pArO9o3nOK9IDvy8Dm46/IMGsiM8XwPtoprAq61VJIcIZwz1+17DPlQDJkfcx3/uw==", + "dev": true, + "dependencies": { + "graphql": "^14.5.3" + } + }, + "node_modules/@types/graphql-list-fields/node_modules/graphql": { + "version": "14.7.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-14.7.0.tgz", + "integrity": "sha512-l0xWZpoPKpppFzMfvVyFmp9vLN7w/ZZJPefUicMCepfJeQ8sMcztloGYY9DfjVPo6tIUDzU5Hw3MUbIjj9AVVA==", + "dev": true, + "dependencies": { + "iterall": "^1.2.2" + }, + "engines": { + "node": ">= 6.x" + } + }, "node_modules/@types/http-assert": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.5.tgz", @@ -7538,6 +7561,11 @@ "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } }, + "node_modules/graphql-list-fields": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/graphql-list-fields/-/graphql-list-fields-2.0.4.tgz", + "integrity": "sha512-q3prnhAL/dBsD+vaGr83B8DzkBijg+Yh+lbt7qp2dW1fpuO+q/upzDXvFJstVsSAA8m11MHGkSxxyxXeLou4MA==" + }, "node_modules/graphql-tag": { "version": "2.12.6", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", diff --git a/luna-backend/package.json b/luna-backend/package.json index f5a43395..369b8105 100644 --- a/luna-backend/package.json +++ b/luna-backend/package.json @@ -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", @@ -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", diff --git a/luna-backend/src/application/business/ambientes/bloco/bloco.resolver.ts b/luna-backend/src/application/business/ambientes/bloco/bloco.resolver.ts index 7d73316c..10753700 100644 --- a/luna-backend/src/application/business/ambientes/bloco/bloco.resolver.ts +++ b/luna-backend/src/application/business/ambientes/bloco/bloco.resolver.ts @@ -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'; @@ -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(info); + return this.blocoService.blocoFindAll(contextoDeAcesso, dto, fields); } // diff --git a/luna-backend/src/application/business/ambientes/bloco/bloco.service.ts b/luna-backend/src/application/business/ambientes/bloco/bloco.service.ts index 9e7a0a9b..13780afb 100644 --- a/luna-backend/src/application/business/ambientes/bloco/bloco.service.ts +++ b/luna-backend/src/application/business/ambientes/bloco/bloco.service.ts @@ -65,7 +65,7 @@ export class BlocoService { // - async blocoFindAll(contextoDeAcesso: IContextoDeAcesso, dto?: Dtos.ISearchInputDto): Promise { + async blocoFindAll(contextoDeAcesso: IContextoDeAcesso, dto?: Dtos.ISearchInputDto, fields: string[] | null = null): Promise { // ========================================================= const qb = this.blocoRepository.createQueryBuilder(aliasBloco); @@ -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(), {