node.jsgraphqlgraphql-jsnode-soap

TypeError: obj.hasOwnProperty is not a function when calling Graphql mutation


I get a strange error and can't figure out what I am doing wrong. I wrote a graphql mutation to call an api:

domainStuff: async (parent, { command, params }, { models }) => {
  console.log("Params:", params);
  const result = await dd24Api(command, params);
  return result;
}

This it the function I call:

export default async (command, parameter) => {
  const args = _.merge({ params: parameter }, auth);
  // Eleminate copying mistakes
  console.log(typeof args);
  const properCommand = command + "Async";
  const result = await soap
    .createClientAsync(apiWSDL)
    .then(client => {
       return client[properCommand](args)
         .then(res => {
            console.log(res[command + "Result"]);
          return res[command + "Result"];
    })
    .catch(err => {
      console.log(err);
      return err;
      });
     })
   .catch(err => console.log(err));

return result;

with this query variables:

{
"command": "CheckDomain",
"params": {"domain": "test.it"}
}

The console.log shows me that args is an object, but I get this error (from the first catch block):

TypeError: obj.hasOwnProperty is not a function

How can that be? After all I checked whether it is an object and it is. More strange, if I give a hardcoded object into the query, this for example:

domainStuff: async (parent, { command, params }, { models }) => {
  console.log("Params:", params);
  const result = await dd24Api(command, {domain: "test.com"});
  return result;
}

then it works perfectly fine. What am I doing wrong? Thx for any help in advance.

EDIT: I am using "graphql-server-express": "^0.8.0" and "graphql-tools": "^1.0.0"


Solution

  • Okay, after an extensive period of trial and error I was able to fix the problem. Changing the position of the objects I pass into the .merge function was the solution. The working code is:

      const args = _.merge(auth, { params: parameter });
    

    Both are objects, but it seems like the object coming from the graphql variables did not have the required hasOwnProperty method. Simply speaking, instead of copying the "good object" (auth) into the bad one (parameter), I copy the bad one into the good one which has the needed function.

    Hopefully this helps someone else who also experiences this error.