Skip to content

Commit

Permalink
node.payload fix (rgstephens#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgstephens authored Dec 9, 2022
1 parent 4af1618 commit 1b612a4
Show file tree
Hide file tree
Showing 5 changed files with 5,281 additions and 135 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ npm install node-red-contrib-graphql

## Change Log

| Vers | Changes | Date |
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| 2.0.0 | GraphQL response is now on `payload.graphql` instead of replacing `payload`. This is a breaking change. Addresses #32 | 7 Dec 2022 |
| 1.4.1 | Bump `follow-redirects` to 1.14.8 | 7 Dec 2022 |
| 1.4.0 | improve debug, bump `follow-redirects` | 30 Jan 2022 |
| 1.3.0 | bump axios to address CVE-2021-3749 | 27 Oct 2021 |
| 1.2.0 | [Fix node not showing in palette](https://github.com/rgstephens/node-red-contrib-graphql/pull/24), bump axios | 14 Sep 2021 |
| 1.1.0 | [Error Handling & Config Templates](https://github.com/rgstephens/node-red-contrib-graphql/pull/11/), [showDebug & customHeaders](https://github.com/rgstephens/node-red-contrib-graphql/pull/22/conflicts), [Bump axios](https://github.com/rgstephens/node-red-contrib-graphql/pull/20) | 15 Jul 2021 |
| 1.0.0 | pass Authorization via msg.authorization, [PR #21](https://github.com/rgstephens/node-red-contrib-graphql/pull/21) | 15 Jul 2021 |
| 0.0.6 | Initial Release | 4 Jun 2018 |
| Vers | Changes |
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 2.0.1 | Update dependencies (`axios` & `mustache`), fix node-red scorecard issues |
| 2.0.0 | GraphQL response is now on `payload.graphql` instead of replacing `payload`. This is a breaking change. Addresses #32 |
| 1.4.1 | Bump `follow-redirects` to 1.14.8 |
| 1.4.0 | improve debug, bump `follow-redirects` |
| 1.3.0 | bump axios to address CVE-2021-3749 |
| 1.2.0 | [Fix node not showing in palette](https://github.com/rgstephens/node-red-contrib-graphql/pull/24), bump axios |
| 1.1.0 | [Error Handling & Config Templates](https://github.com/rgstephens/node-red-contrib-graphql/pull/11/), [showDebug & customHeaders](https://github.com/rgstephens/node-red-contrib-graphql/pull/22/conflicts), [Bump axios](https://github.com/rgstephens/node-red-contrib-graphql/pull/20) |
| 1.0.0 | pass Authorization via msg.authorization, [PR #21](https://github.com/rgstephens/node-red-contrib-graphql/pull/21) |
| 0.0.6 | Initial Release |

## GraphQL Nodes

Expand Down Expand Up @@ -65,7 +66,7 @@ This is the result sent to the debug window.

Here is the example using the [Countries API](https://github.com/trevorblades/countries) built by GitHub user [Trevor Blades](https://github.com/trevorblades), who used [Countries List](https://annexare.github.io/Countries/) as a source of data.

The GraphQL endpoint for this API is `https://countries.trevorblades.com/`
The GraphQL endpoint for this API is `https://countries.trevorblades.com/`. You can try it out [here](https://countries.trevorblades.com/).

```json
# Get information on Germany and it's states
Expand Down
76 changes: 1 addition & 75 deletions examples/countriesFlow.json
Original file line number Diff line number Diff line change
@@ -1,75 +1 @@
[
{
"id": "1e17ed022fe46927",
"type": "graphql",
"z": "f6f2187d.f17ca8",
"name": "Get Country",
"graphql": "5ec8b7409ad68ba9",
"format": "text",
"syntax": "mustache",
"template": "{\n country(code: \"DE\") {\n name\n native\n capital\n currency\n phone\n states {\n code\n name\n }\n }\n}",
"showDebug": false,
"x": 310,
"y": 100,
"wires": [
[
"958145d662bfb358"
],
[
"958145d662bfb358"
]
]
},
{
"id": "6abfe2bcebf7964c",
"type": "inject",
"z": "f6f2187d.f17ca8",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 100,
"wires": [
[
"1e17ed022fe46927"
]
]
},
{
"id": "958145d662bfb358",
"type": "debug",
"z": "f6f2187d.f17ca8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 530,
"y": 100,
"wires": []
},
{
"id": "5ec8b7409ad68ba9",
"type": "graphql-server",
"name": "Countries",
"endpoint": "https://countries.trevorblades.com"
}
]
[{"id":"a12eeec2ef7081f3","type":"graphql","z":"e596e2e15cffe546","name":"Get Country","graphql":"5ec8b7409ad68ba9","format":"json","syntax":"mustache","template":"{\n country(code: \"DE\") {\n name\n native\n capital\n currency\n phone\n states {\n code\n name\n }\n }\n}","showDebug":false,"x":290,"y":80,"wires":[["b1909e0fe42ed002","b4a00ddbf587d5db"],["b4a00ddbf587d5db"]]},{"id":"8ce305107f24099c","type":"inject","z":"e596e2e15cffe546","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["a12eeec2ef7081f3"]]},{"id":"b4a00ddbf587d5db","type":"debug","z":"e596e2e15cffe546","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":100,"wires":[]},{"id":"b1909e0fe42ed002","type":"template","z":"e596e2e15cffe546","name":"Country Details","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Country Name - {{payload.graphql.country.name}} / {{payload.country.native}}\nCapital: {{payload.graphql.country.capital}}\nCurrency: {{payload.graphql.country.currency}}\nStates:\n {{payload.graphql.country.states.0.name}}\n {{payload.graphql.country.states.1.name}}\n {{payload.graphql.country.states.2.name}}\n {{payload.graphql.country.states.3.name}}\n","output":"str","x":520,"y":60,"wires":[["080fbc2ad4668f85"]]},{"id":"080fbc2ad4668f85","type":"debug","z":"e596e2e15cffe546","name":"","active":true,"tosidebar":true,"console":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":60,"wires":[]},{"id":"5ec8b7409ad68ba9","type":"graphql-server","name":"Countries","endpoint":"https://countries.trevorblades.com"}]
5 changes: 3 additions & 2 deletions graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = function(RED) {
var axios = require("axios");
var mustache = require("mustache");

var vers = "2.0.0";
var vers = "2.0.1";

function isReadable(value) {
return typeof value === 'object' && typeof value._read === 'function' && typeof value._readableState === 'object'
Expand Down Expand Up @@ -75,7 +75,7 @@ module.exports = function(RED) {
node.endpoint = config.endpoint;
node.authorization = config.authorization
RED.log.debug("node.endpoint: " + node.endpoint);
RED.log.debug("node.authorization is specified")
RED.log.debug("node.authorization: " + node.authorization)
}

RED.nodes.registerType("graphql-server", GraphqlNode, {
Expand Down Expand Up @@ -400,6 +400,7 @@ module.exports = function(RED) {
shape: "dot",
text: RED._("graphql.status.success")
});
node.msg.payload = {}
node.msg.payload.graphql = response.data.data; // remove .data to see entire response
if (node.showDebug){
node.msg.debugInfo = {
Expand Down
Loading

0 comments on commit 1b612a4

Please sign in to comment.