|
4 | 4 | * This source code is licensed under the MIT license found in the |
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | | -import 'regenerator-runtime/runtime'; |
8 | | - |
| 7 | +import * as GraphiQLReact from '@graphiql/react'; |
9 | 8 | import { createGraphiQLFetcher } from '@graphiql/toolkit'; |
| 9 | +import * as GraphQL from 'graphql'; |
| 10 | +import 'regenerator-runtime/runtime'; |
| 11 | +import { GraphiQL } from './components/GraphiQL'; |
10 | 12 |
|
11 | 13 | import '@graphiql/react/font/roboto.css'; |
12 | 14 | import '@graphiql/react/font/fira-code.css'; |
13 | 15 | import '@graphiql/react/dist/style.css'; |
14 | 16 | import './style.css'; |
15 | 17 |
|
16 | | -import { GraphiQL } from './components/GraphiQL'; |
17 | | - |
18 | | -import { |
19 | | - useEditorContext, |
20 | | - useExecutionContext, |
21 | | - useSchemaContext, |
22 | | -} from '@graphiql/react'; |
| 18 | +/** |
| 19 | + * For the CDN bundle we add some static properties to the component function |
| 20 | + * so that they can be accessed in the inline-script in the HTML file. |
| 21 | + */ |
23 | 22 |
|
24 | | -// add the static function here for CDN only. otherwise, doing this in the component could |
25 | | -// add unwanted dependencies to the bundle. |
| 23 | +/** |
| 24 | + * This function is needed in order to easily create a fetcher function. |
| 25 | + */ |
26 | 26 | // @ts-expect-error |
27 | 27 | GraphiQL.createFetcher = createGraphiQLFetcher; |
| 28 | + |
| 29 | +/** |
| 30 | + * We also add the complete `graphiql-js` exports so that this instance of |
| 31 | + * `graphiql-js` can be reused from plugin CDN bundles. |
| 32 | + */ |
28 | 33 | // @ts-expect-error |
29 | | -GraphiQL.useEditorContext = useEditorContext; |
30 | | -// @ts-expect-error |
31 | | -GraphiQL.useExecutionContext = useExecutionContext; |
| 34 | +GraphiQL.GraphQL = GraphQL; |
| 35 | + |
| 36 | +/** |
| 37 | + * We also add the complete `@graphiql/react` exports. These will be included |
| 38 | + * in the bundle anyways since they make up the `GraphiQL` component, so by |
| 39 | + * doing this we can reuse them from plugin CDN bundles. |
| 40 | + */ |
32 | 41 | // @ts-expect-error |
33 | | -GraphiQL.useSchemaContext = useSchemaContext; |
| 42 | +GraphiQL.React = GraphiQLReact; |
34 | 43 |
|
35 | 44 | export default GraphiQL; |
0 commit comments