Skip to content

Commit

Permalink
update validation to use new object notation
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Jan 30, 2021
1 parent e34115e commit 13c6f1e
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/engine/validation.ts
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import { isObjectDataType, ObjectDataType } from './datatype/ObjectDataType';
import { isListDataType } from './datatype/ListDataType';
import { isListDataType, ListDataType } from './datatype/ListDataType';
import { isComplexDataType } from './datatype/ComplexDataType';
import { isMap, passOrThrow, isDefined, asyncForEach } from './util';
import { MUTATION_TYPE_CREATE, Mutation } from './mutation/Mutation';
Expand All @@ -10,24 +10,26 @@ import { Attribute } from './attribute/Attribute';
import { Context } from './context/Context';
import { Source } from 'graphql';
import { isDataType } from './datatype/DataType';
// import { Attribute } from './attribute/Attribute';

const validateDataTypePayload = async ({
dataType,
payload,
context,
source,
}: {
dataType: DataType | ObjectDataType;
payload: any;
dataType: DataType | ObjectDataType | ListDataType;
payload: unknown;
context?: Context;
source: Source;
}): Promise<void> => {
if (isDataType(dataType)) {
if (
isDataType(dataType) ||
isObjectDataType(dataType) ||
isListDataType(dataType)
) {
const dataTypeValidator = dataType.validate;

if (dataTypeValidator) {
console.log(`==========> ${dataType.name}`);
await dataTypeValidator({ value: payload, context, source });
}
}
Expand Down Expand Up @@ -131,19 +133,16 @@ const validatePayload = async (

if (attributeValidator) {
if (
param.isSystemAttribute ||
attribute.isSystemAttribute ||
typeof payload[attributeName] !== 'undefined'
) {
const result = await attributeValidator(
payload[attributeName],
await attributeValidator({
value: payload[attributeName],
attributeName,
payload,
input: payload,
source,
context,
);
if (result instanceof Error) {
throw result;
}
});
}
}
}
Expand Down

0 comments on commit 13c6f1e

Please sign in to comment.