Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Fix readSelection value setting not respecting schema+cached
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Sep 4, 2019
1 parent 70654f7 commit ac5aa08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/operations/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Query', () => {
);
});

it('test partial results', () => {
it.only('test partial results', () => {
const result = query(store, { query: TODO_QUERY });
expect(result.partial).toBe(true);
expect(result.data).toEqual({
Expand Down
28 changes: 12 additions & 16 deletions src/operations/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,21 @@ const readSelection = (
}
}

// When dataFieldValue is undefined that means that we have to check whether we can continue,
// or whether this Data is now invalid, in which case we return undefined
if (schemaPredicates !== undefined) {
// If we can check against the schema an uncached field may be acceptable for partial results
if (
dataFieldValue === undefined &&
schemaPredicates.isFieldNullable(typename, fieldName)
) {
hasFields = true;
data[fieldAlias] = null;
ctx.partial = true;
} else {
return undefined;
}
if (
dataFieldValue === undefined &&
schemaPredicates !== undefined &&
schemaPredicates.isFieldNullable(typename, fieldName)
) {
// The field is uncached but we have a schema that says it's nullable
// Set the field to null and continue
hasFields = true;
data[fieldAlias] = null;
ctx.partial = true;
} else if (dataFieldValue === undefined) {
// Otherwise an uncached field means that the Data is invalid, so we return undefined
// The field is uncached and not nullable; return undefined
return undefined;
} else {
// Otherwise we can set the field on data and continue
// Otherwise continue as usual
hasFields = true;
data[fieldAlias] = dataFieldValue;
}
Expand Down

0 comments on commit ac5aa08

Please sign in to comment.