Skip to content

Commit 0c8e390

Browse files
authored
graphiql 5: remove readOnly prop, document keyMap prop was removed in migration guide (#4003)
* upd * upd * upd
1 parent 2d9faec commit 0c8e390

File tree

9 files changed

+22
-29
lines changed

9 files changed

+22
-29
lines changed

.changeset/many-ducks-visit.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphiql/react': minor
3+
'graphiql': major
4+
---
5+
6+
remove `readOnly` prop
7+
document `keyMap` prop was removed in migration guide

docs/migration/graphiql-5.0.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
- Added new examples: [**GraphiQL x Vite**](https://github.com/graphql/graphiql/tree/graphiql-5/examples/graphiql-vite) and [**GraphiQL x
1414
Next.js**](https://github.com/graphql/graphiql/tree/graphiql-5/examples/graphiql-nextjs)
1515
- Removed examples: **GraphiQL x Parcel** and **GraphiQL x Create React App**
16+
- UMD build is removed. Use the ESM-based CDN instead.
17+
- Removed props
18+
- `keyMap`. To use Vim or Emacs keybindings in Monaco, you can use community plugins. Monaco Vim: https://github.com/brijeshb42/monaco-vim. Monaco Emacs: https://github.com/aioutecism/monaco-emacs
19+
- `readOnly`

examples/monaco-graphql-nextjs/src/editor.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export default function Editor(): ReactElement {
104104
model: MODEL.ts,
105105
...DEFAULT_EDITOR_OPTIONS,
106106
smoothScrolling: true,
107-
readOnly: false,
108107
'semanticHighlighting.enabled': true,
109108
language: 'typescript',
110109
}),

packages/graphiql-react/src/components/header-editor.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ interface HeaderEditorProps extends EditorProps {
2020
onEdit?(value: string): void;
2121
}
2222

23-
export const HeaderEditor: FC<HeaderEditorProps> = ({
24-
onEdit,
25-
readOnly = false,
26-
...props
27-
}) => {
23+
export const HeaderEditor: FC<HeaderEditorProps> = ({ onEdit, ...props }) => {
2824
const {
2925
initialHeaders,
3026
shouldPersistHeaders,
@@ -51,7 +47,7 @@ export const HeaderEditor: FC<HeaderEditorProps> = ({
5147
useEffect(() => {
5248
const model = getOrCreateModel({ uri: HEADER_URI, value: initialHeaders });
5349
// Build the editor
54-
const editor = createEditor(ref, { model, readOnly });
50+
const editor = createEditor(ref, { model });
5551
setEditor({ headerEditor: editor });
5652
const disposables = [
5753
editor.addAction({ ...KEY_BINDINGS.runQuery, run }),

packages/graphiql-react/src/components/query-editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ interface QueryEditorProps extends EditorProps {
4343
export const QueryEditor: FC<QueryEditorProps> = ({
4444
onClickReference,
4545
onEdit,
46-
readOnly = false,
4746
...props
4847
}) => {
4948
const {
@@ -209,7 +208,7 @@ export const QueryEditor: FC<QueryEditorProps> = ({
209208
useEffect(() => {
210209
globalThis.__MONACO = monaco;
211210
const model = getOrCreateModel({ uri: QUERY_URI, value: initialQuery });
212-
const editor = createEditor(ref, { model, readOnly });
211+
const editor = createEditor(ref, { model });
213212
setEditor({ queryEditor: editor });
214213

215214
// We don't use the generic `useChangeHandler` hook here because we want to

packages/graphiql-react/src/components/response-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ResponseTooltipType = ComponentType<{
2727
word: monacoEditor.IWordAtPosition;
2828
}>;
2929

30-
interface ResponseEditorProps extends Omit<EditorProps, 'readOnly'> {
30+
interface ResponseEditorProps extends EditorProps {
3131
/**
3232
* Customize the tooltip when hovering over properties in the response editor.
3333
*/

packages/graphiql-react/src/components/variable-editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ interface VariableEditorProps extends EditorProps {
2222

2323
export const VariableEditor: FC<VariableEditorProps> = ({
2424
onEdit,
25-
readOnly = false,
2625
...props
2726
}) => {
2827
const { initialVariables, setEditor, run, prettifyEditors, mergeQuery } =
@@ -42,7 +41,7 @@ export const VariableEditor: FC<VariableEditorProps> = ({
4241
uri: VARIABLE_URI,
4342
value: initialVariables,
4443
});
45-
const editor = createEditor(ref, { model, readOnly });
44+
const editor = createEditor(ref, { model });
4645
setEditor({ variableEditor: editor });
4746
const disposables = [
4847
editor.addAction({ ...KEY_BINDINGS.runQuery, run }),

packages/graphiql-react/src/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import {
88
SchemaSlice,
99
} from './stores';
1010

11-
export interface EditorProps extends ComponentPropsWithoutRef<'div'> {
12-
/**
13-
* Makes the editor read-only.
14-
* @default false
15-
*/
16-
readOnly?: boolean;
17-
}
11+
export type EditorProps = ComponentPropsWithoutRef<'div'>;
1812

1913
export interface SchemaReference {
2014
kind: string;

packages/graphiql/src/GraphiQL.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const GraphiQL_: FC<GraphiQLProps> = ({
7070
maxHistoryLength,
7171
plugins = [HISTORY_PLUGIN],
7272
referencePlugin = DOC_EXPLORER_PLUGIN,
73-
readOnly,
7473
onEditQuery,
7574
onEditVariables,
7675
onEditHeaders,
@@ -103,11 +102,14 @@ const GraphiQL_: FC<GraphiQLProps> = ({
103102
'`keyMap` was removed. To use Vim or Emacs keybindings in Monaco, you can use community plugins. Monaco Vim: https://github.com/brijeshb42/monaco-vim. Monaco Emacs: https://github.com/aioutecism/monaco-emacs',
104103
);
105104
}
105+
// @ts-expect-error -- Prop is removed
106+
if (props.readOnly) {
107+
throw new TypeError('`readOnly` was removed.');
108+
}
106109
const interfaceProps: GraphiQLInterfaceProps = {
107110
// TODO check if `showPersistHeadersSettings` prop is needed, or we can just use `shouldPersistHeaders` instead
108111
showPersistHeadersSettings:
109112
showPersistHeadersSettings ?? props.shouldPersistHeaders !== false,
110-
readOnly,
111113
onEditQuery,
112114
onEditVariables,
113115
onEditHeaders,
@@ -212,7 +214,6 @@ const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
212214
confirmCloseTab,
213215
className,
214216
onEditQuery,
215-
readOnly,
216217
onEditVariables,
217218
onEditHeaders,
218219
responseTooltip,
@@ -639,11 +640,7 @@ const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
639640
aria-label="Query Editor"
640641
ref={editorToolsResize.firstRef}
641642
>
642-
<QueryEditor
643-
onClickReference={onClickReference}
644-
onEdit={onEditQuery}
645-
readOnly={readOnly}
646-
/>
643+
<QueryEditor onClickReference={onClickReference} onEdit={onEditQuery} />
647644
<div
648645
className="graphiql-toolbar"
649646
role="toolbar"
@@ -707,13 +704,11 @@ const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
707704
<VariableEditor
708705
className={activeSecondaryEditor === 'variables' ? '' : 'hidden'}
709706
onEdit={onEditVariables}
710-
readOnly={readOnly}
711707
/>
712708
{isHeadersEditorEnabled && (
713709
<HeaderEditor
714710
className={activeSecondaryEditor === 'headers' ? '' : 'hidden'}
715711
onEdit={onEditHeaders}
716-
readOnly={readOnly}
717712
/>
718713
)}
719714
</section>

0 commit comments

Comments
 (0)