From 349fa8edbe64f93ec2bf61e5e6c3b87f428f9c94 Mon Sep 17 00:00:00 2001 From: Mike Surowiec Date: Mon, 7 Jun 2021 12:26:16 -0700 Subject: [PATCH] feat: add react graphql explorer page (#19704) --- components/context/MainContext.tsx | 2 + .../[versionId]/graphql/overview/explorer.tsx | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 pages/[versionId]/graphql/overview/explorer.tsx diff --git a/components/context/MainContext.tsx b/components/context/MainContext.tsx index 050d1460d8..b6b5f251c0 100644 --- a/components/context/MainContext.tsx +++ b/components/context/MainContext.tsx @@ -88,6 +88,7 @@ export type MainContextT = { documentType: string languageVariants: Array<{ name: string; code: string; hreflang: string; href: string }> topics: Array + title: string fullTitle?: string introPlainText?: string hidden: boolean @@ -130,6 +131,7 @@ export const getMainContextFromRequest = (req: any): MainContextT => { page: { languageVariants: req.context.page.languageVariants, documentType: req.context.page.documentType, + title: req.context.page.title, fullTitle: req.context.page.fullTitle, topics: req.context.page.topics || [], introPlainText: req.context.page?.introPlainText, diff --git a/pages/[versionId]/graphql/overview/explorer.tsx b/pages/[versionId]/graphql/overview/explorer.tsx new file mode 100644 index 0000000000..1aea8d0185 --- /dev/null +++ b/pages/[versionId]/graphql/overview/explorer.tsx @@ -0,0 +1,62 @@ +import { GetServerSideProps } from 'next' + +import { + MainContextT, + MainContext, + getMainContextFromRequest, +} from 'components/context/MainContext' +import { Breadcrumbs } from 'components/Breadcrumbs' +import { DefaultLayout } from 'components/DefaultLayout' + +type Props = { + mainContext: MainContextT + graphqlExplorerUrl: string +} +export default function GQLExplorer({ mainContext, graphqlExplorerUrl }: Props) { + const { page, airGap } = mainContext + return ( + + +
+
+
+
+ +
+
+ +

{page.title}

+ +
+
+ {airGap ? ( +

GraphQL explorer is not available on this environment.

+ ) : ( + + )} +
+
+
+
+
+
+ ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const req = context.req as any + + return { + props: { + mainContext: getMainContextFromRequest(req), + graphqlExplorerUrl: req.context.graphql.explorerUrl, + }, + } +}