-
Notifications
You must be signed in to change notification settings - Fork 22
/
graphql.html
179 lines (173 loc) · 7.8 KB
/
graphql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<script type="text/x-red" data-template-name="graphql-server">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-config-input-endpoint"><i class="fa fa-bookmark"></i> <span data-i18n="graphql.label.endpoint"></span></label>
<input type="text" id="node-config-input-endpoint">
</div>
<div class="form-row">
<label for="node-config-input-token"><i class="fa fa-lock"></i> <span data-i18n="graphql.label.token"></span></label>
<input type="text" id="node-config-input-token">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('graphql-server', {
category: 'config',
color: "rgb(218, 196, 180)",
defaults: {
name: { value: "", required: false },
endpoint: { value: "", required: true },
token: { value: "", required: false }
},
credentials: {
token: { type: "password" },
},
credentials: {},
align: 'left',
label: function () {
return this.name || this.endpoint;
}
});
</script>
<script type="text/x-red" data-template-name="graphql">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-input-graphql"><i class="fa fa-globe"></i> <span data-i18n="graphql.label.endpoint"></span></label>
<input type="text" id="node-input-graphql">
</div>
<!-- <div class="form-row">
<label for="node-input-customHeaders"><i class="fa fa-bookmark"></i> <span data-i18n="graphql.label.customHeaders"></span></label>
<input type="json" id="node-input-customHeaders">
</div> -->
<div class="form-row" style="position: relative; margin-bottom: 0px;">
<label for="node-input-template"><i class="fa fa-file-code-o"></i> <span data-i18n="graphql.label.query"></span></label>
<input type="hidden" id="node-input-template" autofocus="autofocus">
<div style="position: absolute; right:0;display:inline-block; text-align: right; font-size: 0.8em;">
<span data-i18n="template.label.format"></span>:
<select id="node-input-format" style="width:110px; font-size: 10px !important; height: 24px; padding:0;">
<option value="handlebars">mustache</option>
<option value="html">HTML</option>
<option value="json">JSON</option>
<option value="markdown">Markdown</option>
<option value="text">none</option>
</select>
</div>
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px;" class="node-text-editor" id="node-input-template-editor" ></div>
</div>
<div class="form-row">
<label for="node-input-syntax"><i class="fa fa-code"></i> <span data-i18n="graphql.label.syntax"></span></label>
<select id="node-input-syntax" style="width:180px;">
<option value="mustache" data-i18n="graphql.label.mustache"><span data-i18n="template.label.mustache"></span></option>
<option value="plain" data-i18n="graphql.label.plain"><span data-i18n="template.label.plain"></span></option>
</select>
</div>
<div class="form-row">
<label for="node-input-token"><i class="fa fa-lock"></i> <span data-i18n="graphql.label.token"></span></label>
<input type="text" id="node-input-token">
</div>
<div class="form-row">
<label for="node-input-showDebug"><i class="fa fa-bookmark"></i> <span data-i18n="graphql.label.showDebug"></span></label>
<input type="checkbox" id="node-input-showDebug">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('graphql', {
category: 'function',
color: '#a6bbcf',
defaults: {
name: { value: "", required: true },
graphql: { type: "graphql-server", required: true },
format: { value: "handlebars", required: false },
template: { value: "{\n country(code: \"NL\") {\n name\n native\n capital\n }\n}", required: true },
syntax: { value: "mustache", required: false },
token: { value: "", required: false },
showDebug: {value: false, required: false}
// customHeaders:{value:"{}", required: false}
},
credentials: {
token: { type: "password" },
},
inputs: 1,
outputs: 2,
icon: "graphql.png",
align: "right",
label: function () {
return this.name || "GraphQL";
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function () {
var that = this;
if (!this.fieldType) {
this.fieldType = 'msg';
}
if (!this.syntax) {
this.syntax = 'mustache';
$("#node-input-syntax").val(this.syntax);
}
if (!this.showDebug) {
// this.showDebug = false;
$("#node-input-showDebug").val(this.showDebug);
}
if (!this.token) {
$("#node-input-token").val(this.token);
}
// $("#node-input-customHeaders").typedInput({
// default: 'json',
// typeField: $("#node-input-customHeaders"),
// label: "msg.customHeaders",
// type:"json",
// types:["json"]
// })
this.editor = RED.editor.createEditor({
id: 'node-input-template-editor',
mode: 'ace/mode/html',
value: $("#node-input-template").val()
});
RED.library.create({
url: "functions", // where to get the data from
type: "function", // the type of object the library is for
editor: that.editor, // the field name the main text body goes to
fields: ['name', 'outputs']
});
this.editor.focus();
$("#node-input-format").change(function () {
var mod = "ace/mode/" + $("#node-input-format").val();
that.editor.getSession().setMode({
path: mod,
v: Date.now()
})
});
},
oneditsave: function () {
$("#node-input-template").val(this.editor.getValue())
delete this.editor;
$("#node-input-showDebug").val(this.showDebug.getValue())
$("#node-input-token").val(this.token.getValue())
},
oneditresize: function (size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i = 0; i < rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height", height + "px");
this.editor.resize();
}
});
</script>
<script type="text/x-red" data-help-name="graphql">
<p>This node executes a GraphQL Query or Mutation</p>
<p>Optionally receives msg.customHeaders to dynamically send headers as needed</p>
<p>Outputs msg.debugInfo if the options is checked</p>
</script>