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