Skip to content

Commit 8a7ffd8

Browse files
authored
fix(explorer): Fix page refresh query history by updating GraphiQL to 3.x (#1397)
1 parent 4e042b7 commit 8a7ffd8

15 files changed

+5367
-4191
lines changed

assets/explorer/.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015", "stage-0", "react"],
3-
"plugins": ["syntax-dynamic-import"]
2+
"presets": [ "@babel/env", "@babel/react" ],
3+
"plugins": [ "syntax-dynamic-import" ]
44
}

assets/explorer/.eslintrc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
{
2-
"parser": "babel-eslint",
3-
"extends": "airbnb/base",
2+
"parser": "@babel/eslint-parser",
3+
"extends": [
4+
"airbnb-base",
5+
"eslint:recommended",
6+
"plugin:react/recommended"
7+
],
8+
"settings": {
9+
"react": {
10+
"version": "detect"
11+
},
12+
"import/resolver": {
13+
"node": {
14+
"extensions": [
15+
".js",
16+
".jsx"
17+
]
18+
}
19+
}
20+
},
21+
"rules": {
22+
"import/no-unresolved": [
23+
2,
24+
{
25+
"ignore": [
26+
"drupal",
27+
"jquery"
28+
]
29+
}
30+
]
31+
},
432
"globals": {
533
"debug": true,
634
"jQuery": true,
7-
"Drupal": true
35+
"Drupal": true,
36+
"once": true
837
}
938
}

assets/explorer/dist/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,67 @@
1-
/*
2-
object-assign
3-
(c) Sindre Sorhus
4-
@license MIT
5-
*/
1+
/*!
2+
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
3+
*
4+
* Copyright (c) 2014-2017, Jon Schlinkert.
5+
* Released under the MIT License.
6+
*/
67

78
/*!
8-
* escape-html
9-
* Copyright(c) 2012-2013 TJ Holowaychuk
10-
* Copyright(c) 2015 Andreas Lubbe
11-
* Copyright(c) 2015 Tiancheng "Timothy" Gu
12-
* MIT Licensed
9+
* is-primitive <https://github.com/jonschlinkert/is-primitive>
10+
*
11+
* Copyright (c) 2014-present, Jon Schlinkert.
12+
* Released under the MIT License.
1313
*/
1414

15-
/** @license React v0.19.1
16-
* scheduler.production.min.js
15+
/*!
16+
* isobject <https://github.com/jonschlinkert/isobject>
17+
*
18+
* Copyright (c) 2014-2017, Jon Schlinkert.
19+
* Released under the MIT License.
20+
*/
21+
22+
/*!
23+
* set-value <https://github.com/jonschlinkert/set-value>
24+
*
25+
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
26+
* Released under the MIT License.
27+
*/
28+
29+
/**
30+
* @license React
31+
* react-dom.production.min.js
1732
*
1833
* Copyright (c) Facebook, Inc. and its affiliates.
1934
*
2035
* This source code is licensed under the MIT license found in the
2136
* LICENSE file in the root directory of this source tree.
2237
*/
2338

24-
/** @license React v16.14.0
25-
* react-dom.production.min.js
39+
/**
40+
* @license React
41+
* react-jsx-runtime.production.min.js
2642
*
2743
* Copyright (c) Facebook, Inc. and its affiliates.
2844
*
2945
* This source code is licensed under the MIT license found in the
3046
* LICENSE file in the root directory of this source tree.
3147
*/
3248

33-
/** @license React v16.14.0
49+
/**
50+
* @license React
3451
* react.production.min.js
3552
*
3653
* Copyright (c) Facebook, Inc. and its affiliates.
3754
*
3855
* This source code is licensed under the MIT license found in the
3956
* LICENSE file in the root directory of this source tree.
4057
*/
58+
59+
/**
60+
* @license React
61+
* scheduler.production.min.js
62+
*
63+
* Copyright (c) Facebook, Inc. and its affiliates.
64+
*
65+
* This source code is licensed under the MIT license found in the
66+
* LICENSE file in the root directory of this source tree.
67+
*/

assets/explorer/dist/container.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
position: relative;
33
height: 650px;
44
}
5+
6+
.graphiql-dialog-overlay,
7+
.graphiql-dialog {
8+
z-index: 101;
9+
}

assets/explorer/dist/graphiql.css

Lines changed: 567 additions & 1627 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/explorer/dist/style.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/explorer/package.json

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,42 @@
33
"scripts": {
44
"clean": "rimraf dist",
55
"build": "npm run clean && NODE_ENV=production webpack && echo \"gzipped, the global build is `gzip -c dist/bundle.min.js | wc -c` bytes\"",
6-
"lint": "eslint src"
6+
"lint": "eslint 'src/**/*.{js,jsx}'",
7+
"dev": "webpack --mode development --watch"
78
},
89
"dependencies": {
9-
"graphiql": "^1.4.2",
10-
"graphiql-explorer": "^0.6.3",
11-
"graphql": "^15.5.1",
12-
"react": "^16.3",
13-
"react-dom": "^16.3"
10+
"@codemirror/language": "6.0.0",
11+
"@graphiql/plugin-explorer": "^2.0.0",
12+
"@graphiql/react": "^0.21.0",
13+
"graphiql": "^3.2.0",
14+
"graphql": "^15.8.0",
15+
"graphql-ws": "^5.16.0",
16+
"prop-types": "^15.8.1",
17+
"react": "^18.2.0",
18+
"react-dom": "^18.2.0",
19+
"react-is": "^16.13.1"
1420
},
1521
"devDependencies": {
16-
"babel": "^6.23.0",
17-
"babel-core": "^6.26.0",
18-
"babel-eslint": "^8.0.2",
19-
"babel-loader": "^7.1.2",
22+
"@babel/cli": "^7.24.1",
23+
"@babel/core": "^7.24.4",
24+
"@babel/eslint-parser": "^7.24.1",
25+
"@babel/preset-env": "^7.24.4",
26+
"@babel/preset-react": "^7.24.1",
27+
"@babel/preset-stage-0": "^7.8.3",
28+
"@babel/register": "^7.23.7",
29+
"babel-loader": "^9.1.3",
2030
"babel-plugin-syntax-dynamic-import": "^6.18.0",
21-
"babel-preset-es2015": "^6.24.1",
22-
"babel-preset-react": "^6.24.1",
23-
"babel-preset-stage-0": "^6.24.1",
2431
"copy-webpack-plugin": "^6.1.2",
25-
"eslint": "^8.9.0",
26-
"eslint-config-airbnb": "^18.1.0",
27-
"eslint-plugin-import": "^2.20.2",
32+
"eslint": "^8.57.0",
33+
"eslint-config-airbnb": "19.0.4",
34+
"eslint-config-airbnb-base": "15.0.0",
35+
"eslint-plugin-import": "^2.25.2",
36+
"eslint-plugin-jsx-a11y": "^6.5.1",
37+
"eslint-plugin-react": "^7.28.0",
38+
"eslint-plugin-react-hooks": "^4.3.0",
2839
"rimraf": "^2.6.2",
29-
"webpack": "^5.40.0",
30-
"webpack-cli": "^4.9.2"
40+
"webpack": "^5.91.0",
41+
"webpack-cli": "^4.9.2",
42+
"webpack-dev-server": "^5.0.4"
3143
}
3244
}

assets/explorer/src/Explorer.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

assets/explorer/src/Explorer.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useState } from 'react';
2+
import { GraphiQL } from 'graphiql';
3+
import { explorerPlugin } from '@graphiql/plugin-explorer';
4+
import PropTypes from 'prop-types';
5+
6+
const Explorer = ({
7+
fetcher, schema, query: q, variables,
8+
}) => {
9+
const [query, setQuery] = useState(q);
10+
11+
const explorer = explorerPlugin();
12+
13+
return (
14+
<div className="graphiql-container">
15+
<GraphiQL
16+
fetcher={fetcher}
17+
plugins={[explorer]}
18+
schema={schema}
19+
query={query}
20+
variables={variables}
21+
onEditQuery={setQuery}
22+
>
23+
<GraphiQL.Logo>
24+
<a
25+
className="graphiql-logo-link"
26+
href="https://www.drupal.org/project/graphql"
27+
target="_blank"
28+
rel="noreferrer"
29+
>
30+
GraphQL
31+
</a>
32+
</GraphiQL.Logo>
33+
</GraphiQL>
34+
</div>
35+
);
36+
};
37+
38+
Explorer.propTypes = {
39+
fetcher: PropTypes.func.isRequired,
40+
schema: PropTypes.object.isRequired,
41+
query: PropTypes.string,
42+
variables: PropTypes.string,
43+
};
44+
45+
export default Explorer;

assets/explorer/src/container.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
position: relative;
33
height: 650px;
44
}
5+
6+
.graphiql-dialog-overlay,
7+
.graphiql-dialog {
8+
z-index: 101;
9+
}

assets/explorer/src/index.js renamed to assets/explorer/src/index.jsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33
import Drupal from 'drupal';
44
import jQuery from 'jquery';
55
import { buildClientSchema } from 'graphql';
@@ -20,21 +20,24 @@ Drupal.behaviors.graphQLRenderExplorer = {
2020
const graphQLSchema = buildClientSchema(settings.graphqlIntrospectionData.data);
2121

2222
// Defines a GraphQL fetcher using the fetch API.
23-
const graphQLFetcher = graphQLParams => fetch(settings.graphqlRequestUrl, {
23+
const graphQLFetcher = (graphQLParams) => fetch(settings.graphqlRequestUrl, {
2424
method: 'post',
2525
credentials: 'same-origin',
2626
body: JSON.stringify(graphQLParams),
2727
headers: {
2828
'Content-Type': 'application/json',
2929
},
30-
}).then(response => response.json());
30+
}).then((response) => response.json());
3131

32-
// Render <Explorer /> into the container.
33-
ReactDOM.render(React.createElement(Explorer, {
34-
fetcher: graphQLFetcher,
35-
schema: graphQLSchema,
36-
query: settings.graphqlQuery || undefined,
37-
variables: settings.graphqlVariables || undefined,
38-
}), container);
32+
const root = createRoot(container);
33+
34+
root.render(
35+
<Explorer
36+
fetcher={graphQLFetcher}
37+
schema={graphQLSchema}
38+
query={settings.graphqlQuery || undefined}
39+
variables={settings.graphqlVariables || undefined}
40+
/>,
41+
);
3942
},
4043
};

assets/explorer/webpack.config.babel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CopyWebpackPlugin from "copy-webpack-plugin";
44

55
module.exports = {
66
context: path.resolve(__dirname, "src"),
7-
entry: "./index.js",
7+
entry: "./index.jsx",
88
output: {
99
path: path.resolve(__dirname, "dist"),
1010
filename: "bundle.min.js",
@@ -23,6 +23,9 @@ module.exports = {
2323
},
2424
],
2525
},
26+
performance: {
27+
hints: false,
28+
},
2629
optimization: {
2730
minimize: true,
2831
},
@@ -33,9 +36,13 @@ module.exports = {
3336
new CopyWebpackPlugin({
3437
patterns: [
3538
{ from: path.resolve(__dirname, "node_modules/graphiql/graphiql.css") },
39+
{ from: path.resolve(__dirname, "node_modules/@graphiql/plugin-explorer/dist/style.css") },
3640
{ from: path.resolve(__dirname, "src/container.css") },
3741
],
3842
}),
43+
new webpack.optimize.LimitChunkCountPlugin({
44+
maxChunks: 1,
45+
}),
3946
],
4047
externals: {
4148
jquery: "jQuery",

0 commit comments

Comments
 (0)