|
6 | 6 | React, |
7 | 7 | ReactDOM, |
8 | 8 | graphqlWs, |
| 9 | + GraphiQLPluginExplorer, |
9 | 10 | fetch, |
10 | 11 | history, |
11 | 12 | location, |
|
98 | 99 | function updateURL() { |
99 | 100 | history.replaceState(null, null, locationQuery(parameters)); |
100 | 101 | } |
101 | | - var options = { |
102 | | - fetcher: graphQLFetcher, |
103 | | - onEditQuery: onEditQuery, |
104 | | - onEditVariables: onEditVariables, |
105 | | - onEditOperationName: onEditOperationName, |
106 | | - isHeadersEditorEnabled: GRAPHENE_SETTINGS.graphiqlHeaderEditorEnabled, |
107 | | - shouldPersistHeaders: GRAPHENE_SETTINGS.graphiqlShouldPersistHeaders, |
108 | | - query: parameters.query, |
109 | | - }; |
110 | | - if (parameters.variables) { |
111 | | - options.variables = parameters.variables; |
112 | | - } |
113 | | - if (parameters.operation_name) { |
114 | | - options.operationName = parameters.operation_name; |
| 102 | + |
| 103 | + function GraphiQLWithExplorer() { |
| 104 | + var [query, setQuery] = React.useState(parameters.query); |
| 105 | + |
| 106 | + function handleQuery(query) { |
| 107 | + setQuery(query); |
| 108 | + onEditQuery(query); |
| 109 | + } |
| 110 | + |
| 111 | + var explorerPlugin = GraphiQLPluginExplorer.useExplorerPlugin({ |
| 112 | + query: query, |
| 113 | + onEdit: handleQuery, |
| 114 | + }); |
| 115 | + |
| 116 | + var options = { |
| 117 | + fetcher: graphQLFetcher, |
| 118 | + plugins: [explorerPlugin], |
| 119 | + defaultEditorToolsVisibility: true, |
| 120 | + onEditQuery: handleQuery, |
| 121 | + onEditVariables: onEditVariables, |
| 122 | + onEditOperationName: onEditOperationName, |
| 123 | + isHeadersEditorEnabled: GRAPHENE_SETTINGS.graphiqlHeaderEditorEnabled, |
| 124 | + shouldPersistHeaders: GRAPHENE_SETTINGS.graphiqlShouldPersistHeaders, |
| 125 | + query: query, |
| 126 | + }; |
| 127 | + if (parameters.variables) { |
| 128 | + options.variables = parameters.variables; |
| 129 | + } |
| 130 | + if (parameters.operation_name) { |
| 131 | + options.operationName = parameters.operation_name; |
| 132 | + } |
| 133 | + |
| 134 | + return React.createElement(GraphiQL, options); |
115 | 135 | } |
| 136 | + |
116 | 137 | // Render <GraphiQL /> into the body. |
117 | 138 | ReactDOM.render( |
118 | | - React.createElement(GraphiQL, options), |
| 139 | + React.createElement(GraphiQLWithExplorer), |
119 | 140 | document.getElementById("editor"), |
120 | 141 | ); |
121 | 142 | })( |
|
126 | 147 | window.React, |
127 | 148 | window.ReactDOM, |
128 | 149 | window.graphqlWs, |
| 150 | + window.GraphiQLPluginExplorer, |
129 | 151 | window.fetch, |
130 | 152 | window.history, |
131 | 153 | window.location, |
|
0 commit comments