Skip to content

Commit

Permalink
Fix payload not init on error case; Fix payload not overwriting primi…
Browse files Browse the repository at this point in the history
…tives (rgstephens#50)
  • Loading branch information
betafcc committed Dec 5, 2023
1 parent 36374fa commit c44e808
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 5,186 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A NodeRed node to execute GraphQL Queries.

| Vers | Changes |
| ----- | -------------------------------------------------------- |
| 2.1.3 | Fix payload not init on error case; Fix payload not overwriting primitives (#50) |
| 2.1.2 | Fix payload init issue |
| 2.1.0 | Bearer Token Authentication |
| 2.0.1 | Update dependencies (`axios` & `mustache`), fix node-red scorecard issues |
Expand Down
6 changes: 4 additions & 2 deletions graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module.exports = function(RED) {
// https://github.com/axios/axios
var axios = require("axios");
var mustache = require("mustache");
var isPlainObject = require("lodash.isplainobject");

var vers = "2.1.2";
var vers = "2.1.3";

function isReadable(value) {
return typeof value === 'object' && typeof value._read === 'function' && typeof value._readableState === 'object'
Expand Down Expand Up @@ -151,7 +152,7 @@ module.exports = function(RED) {
shape: "dot",
text: RED._("graphql.status.success")
});
if (!node.msg.payload) node.msg.payload = {};
if (!isPlainObject(node.msg.payload)) node.msg.payload = {};
node.msg.payload.graphql = response.data.data; // remove .data to see entire response
if (node.showDebug){
node.msg.debugInfo = {
Expand Down Expand Up @@ -189,6 +190,7 @@ module.exports = function(RED) {
.catch(function(error) {
RED.log.debug("error:" + error);
node.status({ fill: "red", shape: "dot", text: "error" });
if (!isPlainObject(node.msg.payload)) node.msg.payload = {};
node.msg.payload.graphql = { error };
node.error("error: " + error);
node.send([null, node.msg]);
Expand Down
Loading

0 comments on commit c44e808

Please sign in to comment.