-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
329 lines (289 loc) · 8.51 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<html>
<head>
<style>
body {
text-align: center;
}
body>p {
margin: 0 20%;
}
#intro {
background: #2d2d2d;
color: #f8f8f8;
}
#intro h1 {
color: #E535AB;
}
#introspection-query {
margin: 0 20%;
text-align: left;
overflow: auto;
max-height: 300px;
}
#introspection-result {
margin: 0 20%;
text-align: left;
overflow: auto;
height: 300px;
width: 60%;
}
#introspection-visualization {
width: 100%;
}
#introspection-visualization>svg {
width: 100%;
height: auto;
}
#download-section {
max-width: 400px;
}
</style>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<!-- Intro -->
<div id="intro" class="jumbotron">
<h1>GraphQL Visualizer</h1>
<p class="lead">
Run the introspection query against a GraphQL endpoint. Paste the result into the textarea below to view the model relationships.
</p>
</div>
<!-- Introspection Query -->
<h2>Introspection Query</h2>
<pre id="introspection-query">query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
args {
...InputValue
}
onOperation
onFragment
onField
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}</pre>
<!-- Introspection Result -->
<h2>Introspection Result</h2>
<textarea id="introspection-result" class="form-control"></textarea>
<!-- Graph Viz -->
<h2>Introspection Visualization</h2>
<div id="introspection-error" class="alert alert-danger" role="alert" style="display: none;"></div>
<div id="introspection-visualization"></div>
<!-- Download Options -->
<h2>Download</h2>
<div id="download-section" class="well center-block">
<button id="download-dot" type="button" class="btn btn-primary btn-lg btn-block">dotfile</button>
<button id="download-svg" type="button" class="btn btn-primary btn-lg btn-block">svg</button>
<button id="download-png" type="button" class="btn btn-primary btn-lg btn-block">png</button>
<button id="download-xdot" type="button" class="btn btn-primary btn-lg btn-block">xdot</button>
<button id="download-plain" type="button" class="btn btn-primary btn-lg btn-block">plain</button>
<button id="download-ps" type="button" class="btn btn-primary btn-lg btn-block">ps</button>
</div>
<div id="png-renderer" style="display: none;"></div>
<!-- FAQ -->
<h2>FAQ</h2>
<div class="well">
<dl>
<dt>What is GraphQL?</dt>
<dd><a target="_blank" href="http://graphql.org/">GraphQL.org</a></dd>
<dt>Is there a CLI version?</dt>
<dd><a target="_blank" href="https://github.com/sheerun/graphqlviz">graphqlviz</a></dd>
<dt>Source & how to contribute?</dt>
<dd>Submit an issue or pull request to the <a href="https://github.com/NathanRSmith/graphql-visualizer">project repo</a></dd>
<dt>Who made this?</dt>
<dd><a target="_blank" href="http://nathanrandal.com/">Nathan Smith</a></dd>
<dt>What libraries are used?</dt>
<dd>
<a target="_blank" href="https://github.com/sheerun/graphqlviz">graphqlviz</a>,
<a target="_blank" href="https://github.com/mdaines/viz.js">Viz.js</a> (<a target="_blank" href="http://www.graphviz.org/">GraphViz</a> compiled to JS),
<a target="_blank" href="https://lodash.com/">Lodash.js</a>,
<a target="_blank" href="http://getbootstrap.com/">Bootstrap</a>,
<a target="_blank" href="https://jquery.com/">JQuery</a>
</dd>
<dt>What is the default visualization?</dt>
<dd><a target="_blank" href="https://github.com/graphql/swapi-graphql">GraphQL wrapper</a> for <a target="_blank" href="http://swapi.co/">SWAPI</a></dd>
</dl>
</div>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/lodash/lodash.min.js"></script>
<script type="text/javascript" src="bower_components/viz.js/viz.js"></script>
<script type="text/javascript" src="js/fixture.js"></script>
<script type="text/javascript" src="js/build-dot.js"></script>
<script type="text/javascript">
var dotfile;
var schema;
// render the svg when the result changes
$('#introspection-result').change(function() {
$('#introspection-error').hide();
dotfile = undefined;
schema = undefined;
$('#introspection-visualization').empty();
try {
schema = JSON.parse($(this).val());
dotfile = buildDot(schema, {});
$('#introspection-visualization').html(Viz(dotfile));
}
catch(err) {
$('#introspection-error').html(err.message).show();
}
});
var DOWNLOADS = {
'#download-dot': {
viz_format: 'dot',
extension: 'graphviz',
handler: function(dotfile, opts) {
return download('graphql-erd.'+opts.extension, dotfile);
}
},
'#download-svg': {
viz_format: 'svg',
extension: 'svg',
},
'#download-xdot': {
viz_format: 'xdot',
extension: 'xdot',
},
'#download-plain': {
viz_format: 'plain',
extension: 'txt',
},
'#download-ps': {
viz_format: 'ps',
extension: 'ps',
},
'#download-png': {
viz_format: 'png-image-element',
extension: 'png',
enc: 'data:image/png;base64',
handler: function(dotfile, opts) {
var image = Viz(dotfile, {format: opts.viz_format});
// gotta wait for the page to figure out the data...
$('#png-renderer').html(image);
setTimeout(function() {
// might be too big for dataurl, so use blob
var blob = b64toBlob(image.src.split(',')[1], 'image/png');
var blobUrl = URL.createObjectURL(blob);
download('graphql-erd.png', null, blobUrl);
}, 0);
}
}
}
// set up download button click handlers
_.each(DOWNLOADS, function(v, k) {
$(k).click(function() {
if(!dotfile) return alert('Please provide a valid introspection.');
if(v.handler) return v.handler(dotfile, v);
download('graphql-erd.'+v.extension, Viz(dotfile, {format: v.viz_format}));
})
})
// trigger a download
function download(filename, text, data) {
var element = document.createElement('a');
if(data) element.setAttribute('href', data);
else element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// http://stackoverflow.com/a/16245768/898830
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
return blob;
}
$('#introspection-result').val(JSON.stringify(SCHEMA_FIXTURE, null, 2)).change();
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-74982267-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>