-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First step of #6868 Adds min.., max.. queries for DATETIME fields adds min.., max.., avg.., sum.. queries for NUMBER fields (count distinct operation and composite fields such as CURRENCY handling will be dealt with in a future PR) <img width="1422" alt="Capture d’écran 2024-11-06 à 15 48 46" src="https://github.com/user-attachments/assets/4bcdece0-ad3e-4536-9720-fe4044a36719"> --------- Co-authored-by: Charles Bochet <[email protected]> Co-authored-by: Weiko <[email protected]>
- Loading branch information
1 parent
c966533
commit a799370
Showing
93 changed files
with
1,584 additions
and
1,172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...l-query-parsers/graphql-query-selected-fields/graphql-selected-fields-aggregate.parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface'; | ||
|
||
import { GraphqlQuerySelectedFieldsResult } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-selected-fields/graphql-selected-fields.parser'; | ||
import { | ||
AggregationField, | ||
getAvailableAggregationsFromObjectFields, | ||
} from 'src/engine/api/graphql/workspace-schema-builder/utils/get-available-aggregations-from-object-fields.util'; | ||
|
||
export class GraphqlQuerySelectedFieldsAggregateParser { | ||
parse( | ||
graphqlSelectedFields: Partial<Record<string, any>>, | ||
fieldMetadataMapByName: Record<string, FieldMetadataInterface>, | ||
accumulator: GraphqlQuerySelectedFieldsResult, | ||
): void { | ||
const availableAggregations: Record<string, AggregationField> = | ||
getAvailableAggregationsFromObjectFields( | ||
Object.values(fieldMetadataMapByName), | ||
); | ||
|
||
for (const selectedField of Object.keys(graphqlSelectedFields)) { | ||
const selectedAggregation = availableAggregations[selectedField]; | ||
|
||
if (!selectedAggregation) { | ||
continue; | ||
} | ||
|
||
accumulator.aggregate[selectedField] = selectedAggregation; | ||
} | ||
} | ||
} |
32 changes: 18 additions & 14 deletions
32
...ql-query-parsers/graphql-query-selected-fields/graphql-selected-fields-relation.parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface'; | ||
|
||
import { GraphqlQuerySelectedFieldsParser } from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-selected-fields/graphql-selected-fields.parser'; | ||
import { | ||
GraphqlQuerySelectedFieldsParser, | ||
GraphqlQuerySelectedFieldsResult, | ||
} from 'src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query-selected-fields/graphql-selected-fields.parser'; | ||
import { getRelationObjectMetadata } from 'src/engine/api/graphql/graphql-query-runner/utils/get-relation-object-metadata.util'; | ||
import { ObjectMetadataMap } from 'src/engine/metadata-modules/utils/generate-object-metadata-map.util'; | ||
import { ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps'; | ||
|
||
export class GraphqlQuerySelectedFieldsRelationParser { | ||
private objectMetadataMap: ObjectMetadataMap; | ||
private objectMetadataMaps: ObjectMetadataMaps; | ||
|
||
constructor(objectMetadataMap: ObjectMetadataMap) { | ||
this.objectMetadataMap = objectMetadataMap; | ||
constructor(objectMetadataMaps: ObjectMetadataMaps) { | ||
this.objectMetadataMaps = objectMetadataMaps; | ||
} | ||
|
||
parseRelationField( | ||
fieldMetadata: FieldMetadataInterface, | ||
fieldKey: string, | ||
fieldValue: any, | ||
result: { select: Record<string, any>; relations: Record<string, any> }, | ||
accumulator: GraphqlQuerySelectedFieldsResult, | ||
): void { | ||
if (!fieldValue || typeof fieldValue !== 'object') { | ||
return; | ||
} | ||
|
||
result.relations[fieldKey] = true; | ||
accumulator.relations[fieldKey] = true; | ||
|
||
const referencedObjectMetadata = getRelationObjectMetadata( | ||
fieldMetadata, | ||
this.objectMetadataMap, | ||
this.objectMetadataMaps, | ||
); | ||
|
||
const relationFields = referencedObjectMetadata.fields; | ||
const relationFields = referencedObjectMetadata.fieldsByName; | ||
const fieldParser = new GraphqlQuerySelectedFieldsParser( | ||
this.objectMetadataMap, | ||
this.objectMetadataMaps, | ||
); | ||
const subResult = fieldParser.parse(fieldValue, relationFields); | ||
const relationAccumulator = fieldParser.parse(fieldValue, relationFields); | ||
|
||
result.select[fieldKey] = { | ||
accumulator.select[fieldKey] = { | ||
id: true, | ||
...subResult.select, | ||
...relationAccumulator.select, | ||
}; | ||
result.relations[fieldKey] = subResult.relations; | ||
accumulator.relations[fieldKey] = relationAccumulator.relations; | ||
accumulator.aggregate[fieldKey] = relationAccumulator.aggregate; | ||
} | ||
} |
Oops, something went wrong.