Skip to content

Commit

Permalink
Fix verify state in compare CLI for multiple entities query
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Oct 11, 2022
1 parent e6e0017 commit 40ab8a2
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/graph-node/src/cli/compare/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export const checkGQLEntityInIPLDState = async (
// Filter __typename key in GQL result.
entityResult = omitDeep(entityResult, '__typename');

// Filter skipped fields in GQL result.
// Filter skipped fields in state comaparison.
skipFields.forEach(({ entity, fields }) => {
if (entityName === entity) {
omitDeep(entityResult, fields);
Expand All @@ -346,24 +346,33 @@ export const checkGQLEntitiesInIPLDState = async (
skipFields: EntitySkipFields[] = []
): Promise<string> => {
// Form entities from state to compare with GQL result
const stateEntities = entitiesResult.map(resultEntity => {
return ipldState[entityName][resultEntity.id];
});
const stateEntities = ipldState[entityName];

// Filter __typename key in GQL result.
entitiesResult = omitDeep(entitiesResult, '__typename');
for (const entityResult of entitiesResult) {
const stateEntity = stateEntities[entityResult.id];

// Filter skipped fields in GQL result.
skipFields.forEach(({ entity, fields }) => {
if (entityName === entity) {
omitDeep(entitiesResult, fields);
omitDeep(stateEntities, fields);
}
});
// Verify state if entity from GQL result is present in state.
if (stateEntity) {
// Filter __typename key in GQL result.
entitiesResult = omitDeep(entityResult, '__typename');

// Filter skipped fields in state comaparison.
skipFields.forEach(({ entity, fields }) => {
if (entityName === entity) {
omitDeep(entityResult, fields);
omitDeep(stateEntity, fields);
}
});

const diff = compareObjects(entitiesResult, stateEntities, rawJson);
const diff = compareObjects(entityResult, stateEntity, rawJson);

return diff;
if (diff) {
return diff;
}
}
}

return '';
};

// obj1: expected
Expand Down

0 comments on commit 40ab8a2

Please sign in to comment.