Skip to content

Commit

Permalink
generate graphql input types for prefilter attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Jun 6, 2022
1 parent aa50f13 commit 0127b38
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/graphqlProtocol/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import {
storageDataTypeCapabilityType,
} from '../engine/constants';
import { isComplexDataType } from '../engine/datatype/ComplexDataType';
import { isArray, isMap } from '../engine/util';
import { isArray, isFunction, isMap } from '../engine/util';
import { isViewEntity, ViewEntity } from '../engine/entity/ViewEntity';
import { isShadowEntity } from '../engine/entity/ShadowEntity';
import { DataTypeBoolean, DataTypeString } from '../engine/datatype/dataTypes';
import { getRegisteredEntity, getRegisteredEntityAttribute } from './registry';
import { generateDataInput } from './io';
import { DataTypeFunction } from '../engine/datatype/DataType';
import { ObjectDataType } from '../engine/datatype/ObjectDataType';
import { AttributesMap } from '../engine/attribute/Attribute';

const AND_OPERATOR = 'AND';
const OR_OPERATOR = 'OR';
Expand Down Expand Up @@ -165,14 +169,41 @@ export const generateFilterInput = (entity, graphRegistry) => {

Object.keys(preFilters).map((preFilterName) => {
const preFilter = preFilters[preFilterName];
// TODO:
// const preFilterParamsInputTypeName = protocolConfiguration.generateFilterPreFilterParamsInputTypeName(
// entity,
// preFilterName,
// );

if (preFilter.attributes) {
// TODO
const preFilterParamsInputTypeName =
protocolConfiguration.generateFilterPreFilterParamsInputTypeName(
entity,
preFilterName,
);

let preFilterAttributesType: AttributesMap;

if (isFunction(preFilter.attributes)) {
const preFilterAttributesTypeFn =
preFilter.attributes as DataTypeFunction;

const generatedType = preFilterAttributesTypeFn({
setup: {
name: preFilterParamsInputTypeName,
description: preFilterParamsInputTypeName,
},
}) as ObjectDataType;

preFilterAttributesType = generatedType.getAttributes();
} else {
preFilterAttributesType = preFilter.attributes;
}

const preFilterInputType = generateDataInput(
preFilterParamsInputTypeName,
preFilterAttributesType,
false,
);

preFilterFields[preFilterName] = {
type: preFilterInputType,
};
} else {
preFilterFields[preFilterName] = {
type: GraphQLBoolean,
Expand Down

0 comments on commit 0127b38

Please sign in to comment.