Files
twenty/packages/twenty-server/src/engine/utils/get-resolver-name.util.ts
T
Etienne 61b9d82950 create groupBy resolver + mock groupBy service (#14530)
To test :

```
query : 
query companiesGroupBy($groupBy: CompanyGroupByInput){
  companiesGroupBy(groupBy: $groupBy){
    groupByDimensionValues
    countEmptyId
    sumAnnualRecurringRevenueAmountMicros
    countEmptyAddress
    percentageEmptySearchVector
  }
}

input : 
{"groupBy": {"name": true, "employees": true, "domainName": {"primaryLinkUrl": true}}}

response : 
{
  "data": {
    "companiesGroupBy": [
      {
        "groupByDimensionValues": [
          "Text 1",
          "twenty.com",
          "1"
        ],
        "countEmptyId": 39,
        "sumAnnualRecurringRevenueAmountMicros": 20,
        "countEmptyAddress": 56,
        "percentageEmptySearchVector": 88
      },
      {
        "groupByDimensionValues": [
          "Long long long long and long text 2",
          "github.com/twentyhq/twenty",
          "2"
        ],
        "countEmptyId": 20,
        "sumAnnualRecurringRevenueAmountMicros": 56,
        "countEmptyAddress": 88,
        "percentageEmptySearchVector": 2
      },
      {
        "groupByDimensionValues": [
          "Text 3",
          "react.dev",
          "3"
        ],
        "countEmptyId": 56,
        "sumAnnualRecurringRevenueAmountMicros": 88,
        "countEmptyAddress": 2,
        "percentageEmptySearchVector": 39
      }
    ]
  }
}
```
closes https://github.com/twentyhq/core-team-issues/issues/1439
2025-09-17 10:23:34 +02:00

54 lines
1.9 KiB
TypeScript

import { type WorkspaceResolverBuilderMethodNames } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { type ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { camelCase } from 'src/utils/camel-case';
import { pascalCase } from 'src/utils/pascal-case';
export const getResolverName = (
objectMetadata: Pick<ObjectMetadataEntity, 'namePlural' | 'nameSingular'>,
type: WorkspaceResolverBuilderMethodNames,
) => {
switch (type) {
case 'findMany':
return `${camelCase(objectMetadata.namePlural)}`;
case 'findOne':
return `${camelCase(objectMetadata.nameSingular)}`;
case 'findDuplicates':
return `${camelCase(objectMetadata.nameSingular)}Duplicates`;
case 'createOne':
return `create${pascalCase(objectMetadata.nameSingular)}`;
case 'createMany':
return `create${pascalCase(objectMetadata.namePlural)}`;
case 'updateOne':
return `update${pascalCase(objectMetadata.nameSingular)}`;
case 'updateMany':
return `update${pascalCase(objectMetadata.namePlural)}`;
case 'deleteOne':
return `delete${pascalCase(objectMetadata.nameSingular)}`;
case 'deleteMany':
return `delete${pascalCase(objectMetadata.namePlural)}`;
case 'destroyOne':
return `destroy${pascalCase(objectMetadata.nameSingular)}`;
case 'destroyMany':
return `destroy${pascalCase(objectMetadata.namePlural)}`;
case 'restoreOne':
return `restore${pascalCase(objectMetadata.nameSingular)}`;
case 'restoreMany':
return `restore${pascalCase(objectMetadata.namePlural)}`;
case 'mergeMany':
return `merge${pascalCase(objectMetadata.namePlural)}`;
case 'groupBy':
return `${camelCase(objectMetadata.namePlural)}GroupBy`;
default:
throw new Error(`Unknown resolver type: ${type}`);
}
};