Skip to content

Commit 59a898c

Browse files
committed
handle null editor value in explorer plugin
1 parent 9a38de2 commit 59a898c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

.changeset/pink-mails-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/plugin-explorer': patch
3+
---
4+
5+
handle null editor in explorer plugin

packages/graphiql-plugin-code-exporter/src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ function GraphiQLCodeExporterPlugin(props: GraphiQLCodeExporterPluginProps) {
2121
);
2222
}
2323

24-
export function codeExporterPlugin(props: GraphiQLCodeExporterPluginProps) {
24+
export function codeExporterPlugin(
25+
props: GraphiQLCodeExporterPluginProps,
26+
): GraphiQLPlugin {
2527
return {
2628
title: 'GraphiQL Code Exporter',
2729
icon: () => (
@@ -42,5 +44,5 @@ export function codeExporterPlugin(props: GraphiQLCodeExporterPluginProps) {
4244
content() {
4345
return <GraphiQLCodeExporterPlugin {...props} />;
4446
},
45-
} as GraphiQLPlugin;
47+
};
4648
}

packages/graphiql-plugin-explorer/src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ function ExplorerPlugin(props: GraphiQLExplorerPluginProps) {
135135
);
136136
// todo: document how to do this!
137137
const handleEditOperation = useCallback(
138-
(value: string) => queryEditor!.setValue(value),
138+
(value: string) => queryEditor?.setValue(value),
139139
[queryEditor],
140140
);
141141

142+
const operationDocument = queryEditor?.getValue() ?? '';
143+
142144
return (
143145
<GraphiQLExplorer
144146
schema={schema}
@@ -150,7 +152,7 @@ function ExplorerPlugin(props: GraphiQLExplorerPluginProps) {
150152
checkboxUnchecked={checkboxUnchecked}
151153
checkboxChecked={checkboxChecked}
152154
styles={styles}
153-
query={queryEditor!.getValue()}
155+
query={operationDocument}
154156
onEdit={handleEditOperation}
155157
{...props}
156158
/>

0 commit comments

Comments
 (0)