Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix graphql ui 1.9.9 #11768 , #11931

Merged
merged 14 commits into from
Jun 30, 2022
41 changes: 16 additions & 25 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Assets/js/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState, useEffect, useRef } from "react";
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
import GraphiQL from "graphiql";
import GraphiQLExplorer from "graphiql-explorer";
import { buildClientSchema, getIntrospectionQuery } from "graphql";
import { GraphiQLToolbarConfig } from "graphiql/dist/components/GraphiQL";

import "graphiql/graphiql.css";
import "../css/graphiql-orchard.css";
Expand Down Expand Up @@ -40,7 +41,6 @@ function fetcher(params: Object): Promise<any> {
}

function App() {
const _graphiql = useRef(null);
// Gets a graphql query from the URL if present and sets it as the default query.
var parameters: any = parseQueryFromUrl(window.location);

Expand Down Expand Up @@ -108,21 +108,29 @@ function App() {
}).join('&');
history.replaceState(null, null, newSearch);
}


const btnToggleExplorer: GraphiQLToolbarConfig = {
additionalContent: (
<GraphiQL.Button
onClick={handleToggleExplorer}
label="Explorer"
title="Toggle Explorer"
/>
),
};

return (
<div className="graphiql-container">
<GraphiQLExplorer
schema={schema}
query={query}
onEdit={handleEditQuery}
onRunOperation={operationName =>
_graphiql.current.handleRunQuery(operationName)
}
explorerIsOpen={explorerIsOpen}
onToggleExplorer={handleToggleExplorer}
/>
{/*@ts-ignore */}
<GraphiQL ref={_graphiql}
<GraphiQL
fetcher={fetcher}
schema={schema}
variables={parameters.variables}
Expand All @@ -131,25 +139,8 @@ function App() {
onEditOperationName={onEditOperationName}
query={query}
onEditQuery={handleEditQuery}
>
<GraphiQL.Toolbar>
<GraphiQL.Button
onClick={() => _graphiql.current.handlePrettifyQuery()}
label="Prettify"
title="Prettify Query (Shift-Ctrl-P)"
/>
<GraphiQL.Button
onClick={() => _graphiql.current.handleToggleHistory()}
label="History"
title="Show History"
/>
<GraphiQL.Button
onClick={handleToggleExplorer}
label="Explorer"
title="Toggle Explorer"
/>
</GraphiQL.Toolbar>
</GraphiQL>
toolbar={btnToggleExplorer}
></GraphiQL>
</div>
);
}
Expand Down
Loading