From 1a1530a7ed4f851fe926de8ef8e4d4fe5274e339 Mon Sep 17 00:00:00 2001 From: Tim Clifford Date: Fri, 15 Oct 2021 15:40:36 +0100 Subject: [PATCH] fact limit to schema and resolver --- services/api/src/resources/fact/resolvers.ts | 5 +++-- services/api/src/resources/fact/sql.ts | 6 +++++- services/api/src/typeDefs.js | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/api/src/resources/fact/resolvers.ts b/services/api/src/resources/fact/resolvers.ts index b326afd26d..8858463d77 100644 --- a/services/api/src/resources/fact/resolvers.ts +++ b/services/api/src/resources/fact/resolvers.ts @@ -8,7 +8,7 @@ import { logger } from '../../loggers/logger'; export const getFactsByEnvironmentId: ResolverFn = async ( { id: environmentId, environmentAuthz }, - { keyFacts }, + { keyFacts, limit }, { sqlClientPool, hasPermission } ) => { const environment = await environmentHelpers( @@ -25,7 +25,8 @@ export const getFactsByEnvironmentId: ResolverFn = async ( sqlClientPool, Sql.selectFactsByEnvironmentId({ environmentId, - keyFacts + keyFacts, + limit }) ); diff --git a/services/api/src/resources/fact/sql.ts b/services/api/src/resources/fact/sql.ts index 1bafe2463a..2773bb876b 100644 --- a/services/api/src/resources/fact/sql.ts +++ b/services/api/src/resources/fact/sql.ts @@ -21,7 +21,7 @@ export const Sql = { .where('f.id', fid) .orderBy('f.id', 'asc') .toString(), - selectFactsByEnvironmentId: ({ environmentId, keyFacts }) => { + selectFactsByEnvironmentId: ({ environmentId, keyFacts, limit }) => { let q = knex('environment_fact as f') .distinct(standardFactReturn) .leftJoin('environment_fact_reference as r', 'r.fid', '=', 'f.id') @@ -31,6 +31,10 @@ export const Sql = { q.where('f.keyFact', keyFacts); } + if (limit) { + q.limit(limit); + } + return q.orderBy('f.id', 'asc').toString() }, insertFact: ({ environment, name, value, source, description, type, category, keyFact }) => diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 4a4691376f..dd081c8743 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -799,7 +799,7 @@ const typeDefs = gql` advancedTasks: [AdvancedTaskDefinition] services: [EnvironmentService] problems(severity: [ProblemSeverityRating], source: [String]): [Problem] - facts(keyFacts: Boolean): [Fact] + facts(keyFacts: Boolean, limit: Int): [Fact] openshift: Openshift openshiftProjectPattern: String kubernetes: Kubernetes