Skip to content

Commit

Permalink
handle custom scalars appearing in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Mar 21, 2023
1 parent 6d3cd68 commit 9b7a8e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/rescript-relay/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,24 @@ function traverse(
var shouldConvertEnum =
typeof instructions["e"] === "string" && !!converters[instructions["e"]];

// This is true for non-arrays that are to be converted
var shouldConvertCustomField =
typeof instructions["c"] === "string" && !!converters[instructions["c"]];

// This is true for arrays that are to be converted. This and the above
// won't be true at the same time.
var shouldConvertCustomFieldArray =
typeof instructions["ca"] === "string" &&
!!converters[instructions["ca"]];

// Special case when this is a custom field that's an array. Ensures we
// don't accidentally move into the array when we're not supposed to.
if (shouldConvertCustomFieldArray && Array.isArray(currentObj[key])) {
newObj = getNewObj(newObj, currentObj);
newObj[key] = currentObj[key].map(converters[instructions["ca"]]);
return newObj;
}

var shouldBlockTraversal = typeof instructions["b"] === "string";
var allowGoingIntoArray = shouldBlockTraversal
? instructions["b"] === "a"
Expand Down

0 comments on commit 9b7a8e8

Please sign in to comment.