{
return await response.json();
};
-export const GraphqlPlayground = () => {
+const extractQueryName = query => {
+ const match = query.match(/^[^{(]+\s([^{\s(]+)/);
+ return match ? match[1] : null;
+};
+
+const extractTableName = query => {
+ const match = query.match(/query\s*\w*\s*{\s*([^({\s]+)/);
+ return match ? match[1].trim() : null;
+};
+
+const bosQuerySnippet = (accountId) => {
+ return {
+ name: `BOS Widget`,
+ language: `JavaScript`,
+ codeMirrorMode: `jsx`,
+ options: [],
+ generate: arg => {
+ const { operationDataList } = arg;
+ const { query } = operationDataList[0];
+ const queryName = extractQueryName(query)
+ const tableName = extractTableName(query)
+ const formattedQuery = query.replace(/\n/g, `\n` + ` `.repeat(2));
+ return `
+const QUERYAPI_ENDPOINT = \`${HASURA_ENDPOINT}\`;
+
+State.init({
+data: []
+});
+
+const query = \`${formattedQuery}\`
+function fetchGraphQL(operationsDoc, operationName, variables) {
+ return asyncFetch(
+ QUERYAPI_ENDPOINT,
+ {
+ method: "POST",
+ headers: { "x-hasura-role": \`${accountId?.replaceAll(".", "_")}\` },
+ body: JSON.stringify({
+ query: operationsDoc,
+ variables: variables,
+ operationName: operationName,
+ }),
+ }
+ );
+ }
+
+ fetchGraphQL(query, "${queryName}", {}).then((result) => {
+ if (result.status === 200) {
+ if (result.body.data) {
+ const data = result.body.data.${tableName};
+ State.update({ data })
+ console.log(data);
+ }
+ }
+ });
+
+const renderData = (a) => {
+ return (
+
+ {JSON.stringify(a)}
+
+ );
+};
+
+const renderedData = state.data.map(renderData);
+return (
+ {renderedData}
+);`;
+ }
+ }
+};
+
+export default () => {
const { indexerDetails } = useContext(IndexerDetailsContext);
+ const snippets = [bosQuerySnippet(indexerDetails.accountId)];
const [query, setQuery] = useState("");
+
const explorerPlugin = useExplorerPlugin({
query,
onEdit: setQuery,
});
+ const exporterPlugin = useExporterPlugin({
+ query,
+ snippets,
+ codeMirrorTheme: 'graphiql',
+ });
+
return (
graphQLFetcher(params, indexerDetails.accountId)}
query={query}
onEditQuery={setQuery}
plugins={[explorerPlugin]}
defaultQuery=""
storage={sessionStorage}
- theme="dark"
+ plugins={[explorerPlugin, exporterPlugin]}
/>
);
diff --git a/frontend/src/components/Playground/index.js b/frontend/src/components/Playground/index.js
index 84abb703b..352a5cd30 100644
--- a/frontend/src/components/Playground/index.js
+++ b/frontend/src/components/Playground/index.js
@@ -1,3 +1,16 @@
-import { GraphqlPlayground } from "./graphiql";
+import dynamic from 'next/dynamic';
+
+const DynamicGraphiQLWithExporter = dynamic(
+ () => import('./graphiql.jsx'),
+ { ssr: false } // This will load the component only on client side
+);
+
+function GraphqlPlayground({ }) {
+ return (
+
+
+
+ );
+}
export default GraphqlPlayground;
diff --git a/frontend/src/pages/_app.tsx b/frontend/src/pages/_app.tsx
index 29885ae68..eecf66fe2 100644
--- a/frontend/src/pages/_app.tsx
+++ b/frontend/src/pages/_app.tsx
@@ -7,6 +7,7 @@ import {
NearSocialBridgeProvider,
} from "near-social-bridge";
import { IndexerDetailsProvider } from '../contexts/IndexerDetailsContext';
+import 'regenerator-runtime/runtime';
overrideLocalStorage();
export default function App({ Component, pageProps }: AppProps) {