From 415dd7b2cb96336160a80912ce2aa6d786b2bdef Mon Sep 17 00:00:00 2001 From: Jay Cammarano <67079013+jaycammarano@users.noreply.github.com> Date: Mon, 16 Aug 2021 19:07:07 -0400 Subject: [PATCH] graphQL Enum for groupby (#7445) Co-authored-by: Rijk van Zanten Co-authored-by: Rijk van Zanten --- api/src/services/graphql.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/src/services/graphql.ts b/api/src/services/graphql.ts index 1edb336880..e80d30c7d9 100644 --- a/api/src/services/graphql.ts +++ b/api/src/services/graphql.ts @@ -806,11 +806,18 @@ export class GraphQLService { return result; }, }); + ReadCollectionTypes[collection.collection].addResolver({ name: `${collection.collection}_aggregated`, type: [AggregatedFunctions[collection.collection]], args: { - groupBy: GraphQLString, + groupBy: schemaComposer.createEnumTC({ + name: `${collection.collection}_group_by`, + values: Object.values(collection.fields).reduce((acc, field) => { + acc[field.field] = { value: field.field }; + return acc; + }, {} as Record), + }), }, resolve: async ({ info, context }: { info: GraphQLResolveInfo; context: Record }) => { const result = await self.resolveQuery(info); @@ -819,6 +826,7 @@ export class GraphQLService { return result; }, }); + if (collection.singleton === false) { ReadCollectionTypes[collection.collection].addResolver({ name: `${collection.collection}_by_id`,