Skip to content

Commit 5b1104a

Browse files
add graphql and @graphiql/react as properties in CDN bundle
1 parent 7732917 commit 5b1104a

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

.changeset/thirty-eyes-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphiql': patch
3+
---
4+
5+
Add the contents of `graphql` and `@graphiql/react` as static properties to the `GraphiQL` component in CDN bundles so that these modules can be reused from plugin CDN bundles.

packages/graphiql/src/cdn.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,41 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import 'regenerator-runtime/runtime';
8-
7+
import * as GraphiQLReact from '@graphiql/react';
98
import { createGraphiQLFetcher } from '@graphiql/toolkit';
9+
import * as GraphQL from 'graphql';
10+
import 'regenerator-runtime/runtime';
11+
import { GraphiQL } from './components/GraphiQL';
1012

1113
import '@graphiql/react/font/roboto.css';
1214
import '@graphiql/react/font/fira-code.css';
1315
import '@graphiql/react/dist/style.css';
1416
import './style.css';
1517

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+
*/
2322

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+
*/
2626
// @ts-expect-error
2727
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+
*/
2833
// @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+
*/
3241
// @ts-expect-error
33-
GraphiQL.useSchemaContext = useSchemaContext;
42+
GraphiQL.React = GraphiQLReact;
3443

3544
export default GraphiQL;

0 commit comments

Comments
 (0)