226cc9eb74
video QA https://github.com/user-attachments/assets/70c37188-2398-43de-bbf6-5882bb79940a --------- Co-authored-by: Charles Bochet <charles@twenty.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import gql from 'graphql-tag';
|
|
import { capitalize } from 'twenty-shared/utils';
|
|
|
|
type GroupByOperationFactoryParams = {
|
|
objectMetadataSingularName: string;
|
|
objectMetadataPluralName: string;
|
|
groupBy: object[];
|
|
filter?: object;
|
|
orderBy?: object[];
|
|
viewId?: string;
|
|
gqlFields?: string;
|
|
};
|
|
|
|
export const groupByOperationFactory = ({
|
|
objectMetadataSingularName,
|
|
objectMetadataPluralName,
|
|
groupBy,
|
|
filter = {},
|
|
orderBy = [],
|
|
viewId,
|
|
gqlFields,
|
|
}: GroupByOperationFactoryParams) => ({
|
|
query: gql`
|
|
query ${capitalize(objectMetadataPluralName)}GroupBy($groupBy: [${capitalize(objectMetadataSingularName)}GroupByInput!]!, $filter: ${capitalize(objectMetadataSingularName)}FilterInput, $orderBy: [${capitalize(objectMetadataSingularName)}OrderByWithGroupByInput!], $viewId: UUID) {
|
|
${objectMetadataPluralName}GroupBy(groupBy: $groupBy, filter: $filter, orderBy: $orderBy, viewId: $viewId) {
|
|
${gqlFields ? gqlFields : ''}
|
|
groupByDimensionValues
|
|
totalCount
|
|
}
|
|
}
|
|
`,
|
|
variables: {
|
|
groupBy,
|
|
filter,
|
|
orderBy,
|
|
...(viewId && { viewId }),
|
|
},
|
|
});
|