Skip to content

Commit

Permalink
Bugfix for validating optimistic updates containing undefined fields
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D24749857

fbshipit-source-id: ddc91365e5b2cd5591d3da7cda4c62212ddd651a
  • Loading branch information
poteto authored and facebook-github-bot committed Nov 5, 2020
1 parent 2075d38 commit 6a1586d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ describe('validateOptimisticResponse', () => {
},
},
variables: null,
shouldWarn: true,
shouldWarn: false,
},
{
name: 'Does not log a warning for client-side schema extensions',
Expand Down
6 changes: 4 additions & 2 deletions packages/relay-runtime/mutations/validateMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ValidationContext = {|

const warning = require('warning');

const hasOwnProperty = Object.prototype.hasOwnProperty;

let validateMutation = () => {};
if (__DEV__) {
const addFieldToDiff = (path: string, diff: Object, isScalar) => {
Expand Down Expand Up @@ -147,15 +149,15 @@ if (__DEV__) {
context.visitedPaths.add(path);
switch (field.kind) {
case 'ScalarField':
if (optimisticResponse.hasOwnProperty(fieldName) === false) {
if (hasOwnProperty.call(optimisticResponse, fieldName) === false) {
addFieldToDiff(path, context.missingDiff, true);
}
return;
case 'LinkedField':
const selections = field.selections;
if (
optimisticResponse[fieldName] === null ||
(Object.hasOwnProperty(fieldName) &&
(hasOwnProperty.call(optimisticResponse, fieldName) &&
optimisticResponse[fieldName] === undefined)
) {
return;
Expand Down

0 comments on commit 6a1586d

Please sign in to comment.