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],