@@ -19,42 +19,42 @@ module.exports = class MiniGraphiQL extends React.Component {
19
19
constructor ( props ) {
20
20
super ( ) ;
21
21
22
+ const query = props . query . replace ( / ^ \s + / , '' ) . replace ( / \s + $ / , '' ) ;
23
+
22
24
// Initialize state
23
25
this . state = {
24
- query : props . query . replace ( / ^ \s + / , '' ) . replace ( / \s + $ / , '' ) ,
26
+ query : query ,
25
27
variables : props . variables ,
26
28
response : null ,
27
- variableToType : null ,
29
+ variableToType : getVariableToType ( props . schema , query )
28
30
} ;
29
31
30
32
this . _editorQueryID = 0 ;
31
33
}
32
34
33
35
render ( ) {
36
+ const editor =
37
+ < QueryEditor
38
+ key = "query-editor"
39
+ schema = { this . props . schema }
40
+ value = { this . state . query }
41
+ onEdit = { this . _handleEditQuery . bind ( this ) }
42
+ runQuery = { this . _runQueryFromEditor . bind ( this ) }
43
+ /> ;
44
+
34
45
return (
35
46
< div className = "miniGraphiQL" >
36
- { this . state . variables ?
47
+ { Object . keys ( this . state . variableToType ) . length > 0 ?
37
48
< div className = "hasVariables" >
38
- < QueryEditor
39
- schema = { this . props . schema }
40
- value = { this . state . query }
41
- onEdit = { this . _handleEditQuery . bind ( this ) }
42
- runQuery = { this . _runQueryFromEditor . bind ( this ) }
43
- />
49
+ { editor }
44
50
< VariableEditor
45
51
value = { this . state . variables }
46
52
variableToType = { this . state . variableToType }
47
53
onEdit = { this . _handleEditVariables . bind ( this ) }
48
54
onRunQuery = { this . _runQuery . bind ( this ) }
49
55
/>
50
56
</ div >
51
- :
52
- < QueryEditor
53
- schema = { this . props . schema }
54
- value = { this . state . query }
55
- onEdit = { this . _handleEditQuery . bind ( this ) }
56
- runQuery = { this . _runQueryFromEditor . bind ( this ) }
57
- />
57
+ : editor
58
58
}
59
59
< ResultViewer value = { this . state . response } />
60
60
</ div >
@@ -556,7 +556,7 @@ function onHasCompletion(cm, data, onHintInformationRender) {
556
556
557
557
function getVariableToType ( schema , documentStr ) {
558
558
if ( ! documentStr || ! schema ) {
559
- return ;
559
+ return { } ;
560
560
}
561
561
562
562
try {
@@ -579,4 +579,6 @@ function getVariableToType(schema, documentStr) {
579
579
} catch ( e ) {
580
580
// ignore
581
581
}
582
+
583
+ return { } ;
582
584
}
0 commit comments