Implement eager load relations on graphqlQueries (#4391)

* Implement eager load relations on graphqlQueries

* Fix tests

* Fixes

* Fixes
This commit is contained in:
Charles Bochet
2024-03-10 23:42:23 +01:00
committed by GitHub
parent 86c0f311f5
commit ec384cc791
42 changed files with 1372 additions and 850 deletions

View File

@ -0,0 +1,36 @@
import { isUndefined } from '@sniptt/guards';
import { FieldType } from '@/object-record/record-field/types/FieldType';
import { FieldMetadataItem } from '../types/FieldMetadataItem';
export const shouldFieldBeQueried = ({
field,
depth,
eagerLoadedRelations,
}: {
field: Pick<FieldMetadataItem, 'name' | 'type'>;
depth?: number;
eagerLoadedRelations?: Record<string, boolean>;
}): any => {
const fieldType = field.type as FieldType;
if (!isUndefined(depth) && depth < 0) {
return false;
}
if (!isUndefined(depth) && depth < 1 && fieldType === 'RELATION') {
return false;
}
if (
fieldType === 'RELATION' &&
!isUndefined(eagerLoadedRelations) &&
(isUndefined(eagerLoadedRelations[field.name]) ||
!eagerLoadedRelations[field.name])
) {
return false;
}
return true;
};