|
| 1 | +import 'graphiql/style.css'; |
| 2 | +import '@graphiql/plugin-explorer/style.css'; |
| 3 | +import { GraphiQL, GraphiQLProps } from 'graphiql'; |
| 4 | +import { DocumentNode, Kind, parse } from 'graphql'; |
1 | 5 | import { explorerPlugin } from '@graphiql/plugin-explorer';
|
2 |
| -import '@graphiql/plugin-explorer/dist/style.css'; |
3 |
| -import { GraphiQL, GraphiQLInterface, GraphiQLProps, GraphiQLProvider } from 'graphiql'; |
4 | 6 | import { Fetcher, FetcherOpts, FetcherParams } from '@graphiql/toolkit';
|
5 | 7 | import { LoadFromUrlOptions, SubscriptionProtocol, UrlLoader } from '@graphql-tools/url-loader';
|
6 |
| -import 'graphiql/graphiql.css'; |
7 |
| -import { DocumentNode, Kind, parse } from 'graphql'; |
8 | 8 | import 'json-bigint-patch';
|
9 |
| -import React, { useMemo, useState } from 'react'; |
| 9 | +import React, { useMemo } from 'react'; |
10 | 10 | import { useUrlSearchParams } from 'use-url-search-params';
|
11 | 11 | import { YogaLogo } from './YogaLogo';
|
12 | 12 | import './styles.css';
|
@@ -134,73 +134,60 @@ export function YogaGraphiQL(props: YogaGraphiQLProps): React.ReactElement {
|
134 | 134 | false,
|
135 | 135 | );
|
136 | 136 |
|
137 |
| - const [query, setQuery] = useState(params['query']?.toString()); |
138 | 137 | const explorer = explorerPlugin({
|
139 | 138 | showAttribution: true,
|
140 | 139 | });
|
141 | 140 |
|
142 |
| - if (props.query && !props.onEditQuery) { |
143 |
| - // eslint-disable-next-line no-console |
144 |
| - console.warn( |
145 |
| - 'If you provide `query` prop, you should also provide `onEditQuery` prop to handle query changes.', |
146 |
| - ); |
147 |
| - } |
148 |
| - |
149 | 141 | return (
|
150 | 142 | <div className="graphiql-container">
|
151 |
| - <GraphiQLProvider |
| 143 | + <GraphiQL |
152 | 144 | // default values that can be override by props
|
153 | 145 | shouldPersistHeaders
|
154 | 146 | plugins={[explorer]}
|
155 | 147 | schemaDescription={true}
|
156 | 148 | inputValueDeprecation={true}
|
157 |
| - query={query} |
| 149 | + isHeadersEditorEnabled |
| 150 | + defaultEditorToolsVisibility |
| 151 | + initialQuery={params['query']?.toString()} |
| 152 | + onEditQuery={(query, ast) => { |
| 153 | + setParams({ |
| 154 | + query, |
| 155 | + }); |
| 156 | + props.onEditQuery?.(query, ast); |
| 157 | + }} |
158 | 158 | {...props}
|
159 | 159 | fetcher={fetcher}
|
160 | 160 | >
|
161 |
| - <GraphiQLInterface |
162 |
| - isHeadersEditorEnabled |
163 |
| - defaultEditorToolsVisibility |
164 |
| - {...props} |
165 |
| - onEditQuery={(query, ast) => { |
166 |
| - setParams({ |
167 |
| - query, |
168 |
| - }); |
169 |
| - setQuery(query); |
170 |
| - props.onEditQuery?.(query, ast); |
171 |
| - }} |
172 |
| - > |
173 |
| - <GraphiQL.Logo> |
174 |
| - <div style={{ display: 'flex', alignItems: 'center' }}> |
175 |
| - {typeof props?.logo === 'string' ? ( |
176 |
| - // if the logo is a string, then it's coming when rendering graphiql as a static page (see render-graphiql) |
177 |
| - <div |
178 |
| - style={{ width: 40, display: 'flex' }} |
179 |
| - dangerouslySetInnerHTML={{ __html: props.logo }} |
180 |
| - /> |
181 |
| - ) : ( |
182 |
| - // otherwise, it's used inside react and we can render it as a component |
183 |
| - <div style={{ width: 40, display: 'flex' }}>{props?.logo || <YogaLogo />}</div> |
184 |
| - )} |
185 |
| - {typeof props?.title === 'string' ? ( |
186 |
| - // if the title is a string, then it's coming when rendering graphiql as a static page (see render-graphiql) |
187 |
| - <span dangerouslySetInnerHTML={{ __html: props.title }} /> |
188 |
| - ) : ( |
189 |
| - // otherwise, it's used inside react and we can render it as a component |
190 |
| - <span> |
191 |
| - {props?.title || ( |
192 |
| - <> |
193 |
| - Yoga Graph |
194 |
| - <em>i</em> |
195 |
| - QL |
196 |
| - </> |
197 |
| - )} |
198 |
| - </span> |
199 |
| - )} |
200 |
| - </div> |
201 |
| - </GraphiQL.Logo> |
202 |
| - </GraphiQLInterface> |
203 |
| - </GraphiQLProvider> |
| 161 | + <GraphiQL.Logo> |
| 162 | + <div style={{ display: 'flex', alignItems: 'center' }}> |
| 163 | + {typeof props?.logo === 'string' ? ( |
| 164 | + // if the logo is a string, then it's coming when rendering graphiql as a static page (see render-graphiql) |
| 165 | + <div |
| 166 | + style={{ width: 40, display: 'flex' }} |
| 167 | + dangerouslySetInnerHTML={{ __html: props.logo }} |
| 168 | + /> |
| 169 | + ) : ( |
| 170 | + // otherwise, it's used inside react and we can render it as a component |
| 171 | + <div style={{ width: 40, display: 'flex' }}>{props?.logo || <YogaLogo />}</div> |
| 172 | + )} |
| 173 | + {typeof props?.title === 'string' ? ( |
| 174 | + // if the title is a string, then it's coming when rendering graphiql as a static page (see render-graphiql) |
| 175 | + <span dangerouslySetInnerHTML={{ __html: props.title }} /> |
| 176 | + ) : ( |
| 177 | + // otherwise, it's used inside react and we can render it as a component |
| 178 | + <span> |
| 179 | + {props?.title || ( |
| 180 | + <> |
| 181 | + Yoga Graph |
| 182 | + <em>i</em> |
| 183 | + QL |
| 184 | + </> |
| 185 | + )} |
| 186 | + </span> |
| 187 | + )} |
| 188 | + </div> |
| 189 | + </GraphiQL.Logo> |
| 190 | + </GraphiQL> |
204 | 191 | </div>
|
205 | 192 | );
|
206 | 193 | }
|
0 commit comments