From dc850c115e01cfd314997925f00290e30acd56bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Varela?= Date: Fri, 15 Jul 2022 18:13:45 +0100 Subject: [PATCH] Use same types as `count` for `countDistinct` (#14460) --- api/src/services/graphql/index.ts | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/api/src/services/graphql/index.ts b/api/src/services/graphql/index.ts index 852cfcd459..9c837bdf0c 100644 --- a/api/src/services/graphql/index.ts +++ b/api/src/services/graphql/index.ts @@ -834,6 +834,18 @@ export class GraphQLService { }, {} as ObjectTypeComposerFieldConfigMapDefinition), }); + const countType = schemaComposer.createObjectTC({ + name: `${collection.collection}_aggregated_count`, + fields: Object.values(collection.fields).reduce((acc, field) => { + acc[field.field] = { + type: GraphQLInt, + description: field.note, + }; + + return acc; + }, {} as ObjectTypeComposerFieldConfigMapDefinition), + }); + AggregateMethods[collection.collection] = { group: { name: 'group', @@ -845,17 +857,11 @@ export class GraphQLService { }, count: { name: 'count', - type: schemaComposer.createObjectTC({ - name: `${collection.collection}_aggregated_count`, - fields: Object.values(collection.fields).reduce((acc, field) => { - acc[field.field] = { - type: GraphQLInt, - description: field.note, - }; - - return acc; - }, {} as ObjectTypeComposerFieldConfigMapDefinition), - }), + type: countType, + }, + countDistinct: { + name: 'countDistinct', + type: countType, }, }; @@ -879,10 +885,6 @@ export class GraphQLService { name: 'sum', type: AggregatedFields[collection.collection], }, - countDistinct: { - name: 'countDistinct', - type: AggregatedFields[collection.collection], - }, avgDistinct: { name: 'avgDistinct', type: AggregatedFields[collection.collection],