Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Guard against event objects in Mutate callback
Browse files Browse the repository at this point in the history
  • Loading branch information
slaskis committed Nov 29, 2017
1 parent 5a2e529 commit 3db8636
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Mutate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";
import PropTypes from "prop-types";

import isPlainObject from "./isPlainObject";

/**
* Example:
*
Expand Down Expand Up @@ -38,6 +40,11 @@ export class Mutate extends React.Component {
}

mutate(variables) {
// special case for when vars are event
// ex. <button onClick={mutate} />
if (!isPlainObject(variables)) {
variables = undefined;
}
const { client } = this.context.apollo;
const { gql, refetchQueries, optimisticResponse, update } = this.props;
const req = client.mutate({
Expand Down
5 changes: 3 additions & 2 deletions Query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";
import PropTypes from "prop-types";

import isPlainObject from "./isPlainObject";

/**
* Example:
*
Expand Down Expand Up @@ -100,8 +102,7 @@ export class Query extends React.Component {
if (this.observable) {
// special case for when vars are event
// ex. <button onClick={refetch} />
const isPlainObj = typeof vars == "object" && vars.constructor == Object;
return this.observable.refetch(isPlainObj ? vars : undefined);
return this.observable.refetch(isPlainObject(vars) ? vars : undefined);
}
}

Expand Down
1 change: 1 addition & 0 deletions isPlainObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default obj => typeof obj === "object" && obj.constructor === Object;

0 comments on commit 3db8636

Please sign in to comment.