Skip to content

Commit d67d11d

Browse files
authored
add plugins to webpack dev bundle (#3403)
1 parent 31ded5e commit d67d11d

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

packages/graphiql/resources/index.html.ejs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This source code is licensed under the license found in the
66
* LICENSE file in the root directory of this source tree.
77
-->
8-
<!DOCTYPE html>
8+
<!doctype html>
99
<html lang="en">
1010
<head>
1111
<title>GraphiQL</title>
@@ -28,20 +28,30 @@
2828
If you do not want to rely on a CDN, you can host these files locally or
2929
include them directly in your favored resource bundler.
3030
-->
31-
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
32-
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
33-
31+
<script
32+
crossorigin
33+
src="https://unpkg.com/react@18/umd/react.development.js"
34+
></script>
35+
<script
36+
crossorigin
37+
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
38+
></script>
39+
<link rel="stylesheet" href="/plugins/explorer/style.css" />
3440
<!--
35-
These two files can be found in the npm module, however you may wish to
36-
copy them directly into your environment, or perhaps include them in your
37-
favored resource bundler.
38-
-->
41+
These two files can be found in the npm module, however you may wish to copy
42+
them directly into your environment, or perhaps include them in your favored
43+
resource bundler. -->
3944
</head>
4045
<body>
4146
<div id="graphiql">Loading...</div>
4247
<script type="application/javascript">
4348
window.GraphQLVersion = <%= htmlWebpackPlugin.options.graphqlVersion %>
4449
</script>
50+
<script
51+
defer
52+
src="/plugins/explorer/index.umd.js"
53+
type="application/javascript"
54+
></script>
4555
<script
4656
defer
4757
src="/resources/renderExample.js"

packages/graphiql/resources/renderExample.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function getSchemaUrl() {
8383
// how you can customize GraphiQL by providing different values or
8484
// additional child elements.
8585
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
86-
86+
const explorerPlugin = window.GraphiQLPluginExplorer.explorerPlugin();
8787
root.render(
8888
React.createElement(GraphiQL, {
8989
fetcher: GraphiQL.createFetcher({
@@ -102,5 +102,6 @@ root.render(
102102
shouldPersistHeaders: true,
103103
inputValueDeprecation: GraphQLVersion.includes('15.5') ? undefined : true,
104104
onTabChange,
105+
plugins: [explorerPlugin],
105106
}),
106107
);

packages/graphiql/test/beforeDevServer.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ const path = require('node:path');
1010
const { createHandler } = require('graphql-http/lib/use/express');
1111
const schema = require('./schema');
1212
const { schema: badSchema } = require('./bad-schema');
13+
const { readdirSync } = require('node:fs');
14+
15+
const plugins = readdirSync(path.join(__dirname, '../../'))
16+
.filter(
17+
p => p.startsWith('graphiql-plugin-') && p !== 'graphiql-plugin-utils',
18+
)
19+
.map(p => ({ path: p, pluginName: p.replace('graphiql-plugin-', '') }));
1320

1421
module.exports = function beforeDevServer(app, _server, _compiler) {
1522
// GraphQL Server
@@ -27,4 +34,10 @@ module.exports = function beforeDevServer(app, _server, _compiler) {
2734
'/resources/renderExample.js',
2835
express.static(path.join(__dirname, '../resources/renderExample.js')),
2936
);
37+
for (const plugin of plugins) {
38+
app.use(
39+
`/plugins/${plugin.pluginName}/`,
40+
express.static(path.join(__dirname, `../../${plugin.path}/dist/`)),
41+
);
42+
}
3043
};

0 commit comments

Comments
 (0)