-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
239 lines (214 loc) · 6.23 KB
/
index.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE>
<html>
<head>
<title>GraphQL + Haxe Demo</title>
<style>
body { background-color: #f5f3f3; padding:10px; margin:0; font-family: Arial }
.cont {
position: relative;
display:inline-block;
width: 33%;
height:calc(100% - 40px);
padding: 10px;
box-sizing: border-box;
vertical-align:top;
}
.cont > * {
position:relative;
display:block;
width:100%;
height:100%;
}
.cont textarea {
overflow:auto;
resize: none;
background-color:#f3f3f3;
color:#445;
padding:5px;
}
div.cont pre {
overflow:auto;
margin:0;
box-sizing:border-box;
border: 1px solid #eee;
}
.err-loc {
position:absolute;
display:none;
top:0;left:0;
width:10px; height:20px;
background-color:rgba(255,0,0,0.3);
pointer-events:none;
z-index:2;
}
.labels { white-space:nowrap; }
.labels span {
display: inline-block;
width: 33%;
font-size: 26px;
font-weight: bold;
color: #8e0a0a;
padding-left: 10px;
box-sizing: border-box;
white-space:nowrap;
overflow:hidden;
}
.labels a { color: #8e0a0a; transition: color 0.15s linear; }
.labels a:hover { color: #4896dc }
.github-link { position:fixed; width:80px; height:80px; top:0; right:0; z-index:2; }
.github-link span {
display: inline-block;
position: relative;
transform: rotate(45deg) translate(-1px, 19px);
padding: 5px 35px;
color: #fff;
background-color: #a00;
font-weight: bold;
text-shadow: 0 0 3px #500;
letter-spacing: 0.5px;
font-family: sans-serif;
border: 2px solid #fff;
outline: 1px solid #a00;
}
@media (max-width: 1024px) {
.labels span { width:50%; }
.labels span:nth-child(2) { display:none; }
.cont { width: 50%; }
.cont.parse { display:none; }
}
</style>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/agate.min.css" rel="stylesheet"/>
</head>
<body>
<a class="github-link" href="https://github.com/jcward/haxe-graphql"><span>Github</span></a>
<div class="labels">
<span>Enter GraphQL here</span>
<span>gql2ast / Parser.hx</span>
<span>gql2hx / HaxeGenerator.hx</span>
</div>
<div class="cont"><div class="err-loc"></div>
<textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"># Creates typedefs for all schema types
schema {
query: MyQueries
mutation: MyMutations
}
scalar Date
enum ReleaseStatus {
PRE_PRODUCTION
IN_PRODUCTION
RELEASED
}
interface IHaveID {
id:ID!
}
type FilmData implements IHaveID {
id:ID!
title:String!
director:String
releaseDate:Date
releaseStatus:ReleaseStatus
}
# - Queries - -
type MyQueries {
film: [FilmData]
}
# Creates query response typedefs
query GetFilmsByDirector($director: String) {
film(director: $director) {
title
director
releaseDate
}
}
# - Mutations - -
type MyMutations {
insert_film(title:String!, director:String, releaseDate:Date, releaseStatus:ReleaseStatus): FilmData
}
mutation InsertFilm($title:String!, $director:String, $releaseDate:Date, $releaseStatus:ReleaseStatus) {
insert_film(title: $title, director: $director, releaseDate: $releaseDate, releaseStatus: $releaseStatus) { id }
}
</textarea></div><div class="cont parse">
<pre class="agate json"><code></code></pre>
</div><div class="cont gen">
<pre class="agate haxe"><code></code></pre>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/haxe.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/json.min.js"></script>
<script src="gql2hx_demo.js"></script>
<script>
$("textarea").bind('input propertychange',update);
$("textarea").bind('keydown', function(e) {
// https://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start)
+ " "
+ $(this).val().substring(end));
// put caret at right position again
this.selectionStart =
this.selectionEnd = start + 2;
update();
}
});
function update() {
var code_pre = $(".cont.gen pre")[0];
var json_pre = $(".cont.parse pre")[0];
var graphql = $("textarea").val();
$(".cont.parse pre code")[0].innerText = '{}';
$(".cont.gen pre code")[0].innerText = '// Haxe code';
$('.err-loc').css('display','none');
var doc = {}
json_pre.className = 'agate json';
try {
var doc = window.Demo.parse(graphql);
$(json_pre).find('code').text(JSON.stringify(doc, removeLocNull, ' '));
hljs.highlightBlock(json_pre);
} catch (e) {
// Parse error
var msg = ''+e;
if (window.innerWidth>1024) {
$(json_pre).find('code').text(msg);
$(code_pre).find('code').text('// Parse error, cannot generate code');
} else {
$(json_pre).find('code').text();
$(code_pre).find('code').text(msg+'\n\n// Parse error, cannot generate code');
}
var m = msg.match(/(\d+): characters (\d+)/);
if (m) {
// Error loc hack: pixels per character :P
var width_per_char = 8.0;
var height_per_char = 15;
$('.err-loc').css('display','block');
$('.err-loc').css('top',14+height_per_char*(m[1]-1)).css('left',15+width_per_char*(m[2]-1))
}
return;
}
var result = { stderr:'', stdout:'' };
try {
result = window.Demo.hxgen(doc);
} catch (e) {
result = { stderr:''+e };
}
if (result.stderr.length>0) {
code_pre.className = 'agate haxe';
$(code_pre).find('code').text('// HaxeGenerator error:\n\n// '+result.stderr);
} else {
code_pre.className = 'agate haxe';
$(code_pre).find('code').text(result.stdout);
}
hljs.highlightBlock(code_pre);
}
update();
function removeLocNull(name, val) {
if (name=="loc" && val==null) return undefined;
return val;
}
</script>
</html>