Skip to content

Commit 0993ea4

Browse files
committed
Merge branch 'main' into graphiql-5
2 parents 9fc4b21 + 60d5bbc commit 0993ea4

File tree

7 files changed

+694
-794
lines changed

7 files changed

+694
-794
lines changed

docs/migration/graphiql-5.0.0.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Upgrading `graphiql` from `4.x` to `5.0.0-rc`
2+
3+
---
4+
5+
## `graphiql`
6+
7+
- Migration from Codemirror to
8+
[Monaco Editor](https://github.com/microsoft/monaco-editor)
9+
- Replacing `codemirror-graphql` with
10+
[`monaco-graphql`](https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql)
11+
- Clicking on a reference in the query editor now works by holding `Cmd` on macOS or `Ctrl` on Windows/Linux
12+
- Support for comments in **Variables** and **Headers** editors
13+
- Added new examples: [**GraphiQL x Vite**](https://github.com/graphql/graphiql/tree/graphiql-5/examples/graphiql-vite) and [**GraphiQL x
14+
Next.js**](https://github.com/graphql/graphiql/tree/graphiql-5/examples/graphiql-nextjs)
15+
- Removed examples: **GraphiQL x Parcel** and **GraphiQL x Create React App**

examples/graphiql-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"style-loader": "^3.3.1",
3737
"webpack": "5.94.0",
3838
"webpack-cli": "^6.0.1",
39-
"webpack-dev-server": "^4.11.1",
39+
"webpack-dev-server": "^5.2.1",
4040
"webpack-manifest-plugin": "^5.0.0",
4141
"workbox-webpack-plugin": "^7.0.0",
4242
"worker-loader": "^2.0.0"

examples/graphiql-webpack/src/index.jsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import 'regenerator-runtime/runtime.js';
2-
import * as React from 'react';
2+
import React, { useState, useEffect, useMemo } from 'react';
33
import { createRoot } from 'react-dom/client';
44
import { GraphiQL } from 'graphiql';
55
import { explorerPlugin } from '@graphiql/plugin-explorer';
66
import { getSnippets } from './snippets';
77
import { codeExporterPlugin } from '@graphiql/plugin-code-exporter';
8-
import 'graphiql/setup-workers/webpack';
98
import { createGraphiQLFetcher } from '@graphiql/toolkit';
109
import { useStorage } from '@graphiql/react';
10+
import { serverSelectPlugin, LAST_URL_KEY } from './select-server-plugin';
11+
import 'graphiql/setup-workers/webpack';
12+
import './index.css';
1113

1214
export const STARTING_URL = 'https://countries.trevorblades.com';
1315

14-
import './index.css';
15-
import { serverSelectPlugin, LAST_URL_KEY } from './select-server-plugin';
16-
1716
if ('serviceWorker' in navigator) {
1817
window.addEventListener('load', () => {
1918
navigator.serviceWorker
2019
.register('/service-worker.js')
2120
.then(registration => {
22-
console.log('SW registered: ', registration);
21+
console.log('SW registered:', registration);
2322
})
2423
.catch(registrationError => {
25-
console.log('SW registration failed: ', registrationError);
24+
console.error('SW registration failed:', registrationError);
2625
});
2726
});
2827
}
@@ -56,24 +55,21 @@ const style = { height: '100vh' };
5655
*/
5756
const explorer = explorerPlugin();
5857

59-
const App = () => {
60-
// TODO: `storage` will be always `null`, fix it to have access outside `StorageContextProvider` after zustand migration
61-
const storage = useStorage();
62-
const lastUrl = storage?.get(LAST_URL_KEY);
63-
const [currentUrl, setUrl] = React.useState(lastUrl ?? STARTING_URL);
58+
function App() {
59+
const [currentUrl, setUrl] = useState('');
6460
// TODO: a breaking change where we make URL an internal state concern, and then expose hooks
6561
// so that you can handle/set URL state internally from a plugin
6662
// fetcher could then pass a dynamic URL config object to the fetcher internally
67-
const exporter = React.useMemo(
63+
const exporter = useMemo(
6864
() =>
6965
codeExporterPlugin({ snippets: getSnippets({ serverUrl: currentUrl }) }),
7066
[currentUrl],
7167
);
72-
const fetcher = React.useMemo(
68+
const fetcher = useMemo(
7369
() => createGraphiQLFetcher({ url: currentUrl }),
7470
[currentUrl],
7571
);
76-
const serverSelect = React.useMemo(
72+
const serverSelect = useMemo(
7773
() => serverSelectPlugin({ url: currentUrl, setUrl }),
7874
[currentUrl],
7975
);
@@ -84,9 +80,26 @@ const App = () => {
8480
plugins={[serverSelect, explorer, exporter]}
8581
fetcher={fetcher}
8682
shouldPersistHeaders
87-
/>
83+
>
84+
<GraphiQLStorageBound setUrl={setUrl} />
85+
</GraphiQL>
8886
);
89-
};
87+
}
88+
89+
/**
90+
* `useStorage` is a context hook that's only available within the `<GraphiQL>`
91+
* provider tree. `<GraphiQLStorageBound>` must be rendered as a child of `<GraphiQL>`.
92+
*/
93+
function GraphiQLStorageBound({ setUrl }) {
94+
const storage = useStorage();
95+
const lastUrl = storage.get(LAST_URL_KEY) ?? STARTING_URL;
96+
97+
useEffect(() => {
98+
setUrl(lastUrl);
99+
}, [lastUrl, setUrl]);
100+
101+
return null;
102+
}
90103

91104
const root = createRoot(document.getElementById('root'));
92105
root.render(<App />);

examples/monaco-graphql-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
"webpack": "5.76.0",
4040
"webpack-bundle-analyzer": "^3.6.1",
4141
"webpack-cli": "^5.0.1",
42-
"webpack-dev-server": "^4.11.1"
42+
"webpack-dev-server": "^5.2.1"
4343
}
4444
}

packages/graphiql/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
- @graphiql/plugin-history@0.3.0-rc.0
5050
- @graphiql/react@0.35.0-rc.0
5151

52+
## 4.1.2
53+
54+
### Patch Changes
55+
56+
- [#3993](https://github.com/graphql/graphiql/pull/3993) [`70d2216`](https://github.com/graphql/graphiql/commit/70d22164d67b925f3342800161a2b568997bd689) Thanks [@dimaMachina](https://github.com/dimaMachina)! - fix `TypeError: Cannot read properties of null (reading 'get')` and update graphiql webpack example to show how to use `useStorage` hook with `GraphiQL` component
57+
5258
## 4.1.1
5359

5460
### Patch Changes

packages/graphiql/src/GraphiQL.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
300300
logo?: ReactNode;
301301
toolbar?: ReactNode;
302302
footer?: ReactNode;
303+
children: ReactNode[];
303304
}>(
304305
(acc, curr) => {
305306
switch (getChildComponentType(curr)) {
@@ -312,12 +313,15 @@ const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
312313
case GraphiQL.Footer:
313314
acc.footer = curr;
314315
break;
316+
default:
317+
acc.children.push(curr);
315318
}
316319
return acc;
317320
},
318321
{
319322
logo: <GraphiQL.Logo />,
320323
toolbar: <GraphiQL.Toolbar />,
324+
children: [],
321325
},
322326
);
323327

0 commit comments

Comments
 (0)