Avoid setting null entity properties while fetching in store get API (#75)

This commit is contained in:
prathamesh0 2021-12-08 18:36:01 +05:30 committed by nabarun
parent 3b835e81f8
commit 4c422e3ea2

View File

@ -383,13 +383,19 @@ export const getSubgraphConfig = async (subgraphPath: string): Promise<any> => {
export const toEntityValue = async (instanceExports: any, entityInstance: any, data: any, field: ColumnMetadata, type: string) => {
const { __newString, Value } = instanceExports;
const { isArray, propertyName } = field;
const { isArray, propertyName, isNullable } = field;
const entityKey = await __newString(propertyName);
const entityValuePtr = await entityInstance.get(entityKey);
const subgraphValue = Value.wrap(entityValuePtr);
const value = data[propertyName];
// Check if the entity property is nullable.
// No need to set the property if the value is null as well.
if (isNullable && value === null) {
return;
}
const entityValue = await formatEntityValue(instanceExports, subgraphValue, type, value, isArray);
return entityInstance.set(entityKey, entityValue);