diff --git a/pages/[versionId]/graphql/overview/breaking-changes.tsx b/pages/[versionId]/graphql/overview/breaking-changes.tsx index e08ea99706..4fff89b3cf 100644 --- a/pages/[versionId]/graphql/overview/breaking-changes.tsx +++ b/pages/[versionId]/graphql/overview/breaking-changes.tsx @@ -1,61 +1 @@ -import { GetServerSideProps } from 'next' -import React from 'react' - -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' -import { AutomatedPage } from 'components/article/AutomatedPage' -import { - AutomatedPageContext, - AutomatedPageContextT, - getAutomatedPageContextFromRequest, -} from 'components/context/AutomatedPageContext' -import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js' -import { BreakingChanges } from 'components/graphql/BreakingChanges' -import { BreakingChangesT } from 'components/graphql/types' -import { getGraphqlBreakingChanges } from 'src/graphql/lib/index.js' - -type Props = { - mainContext: MainContextT - schema: BreakingChangesT - automatedPageContext: AutomatedPageContextT -} - -export default function GraphqlBreakingChanges({ - mainContext, - schema, - automatedPageContext, -}: Props) { - return ( - - - - - - - - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as any - const res = context.res as any - const currentVersion = context.query.versionId as string - const schema = getGraphqlBreakingChanges(currentVersion) - if (!schema) throw new Error(`No graphql breaking changes schema found for ${currentVersion}`) - - // Gets the miniTocItems in the article context. At this point it will only - // include miniTocItems that exist in Markdown pages in - // content/graphql/reference/* - const automatedPageContext = getAutomatedPageContextFromRequest(req) - const titles = Object.keys(schema).map((item) => `Changes scheduled for ${item}`) - const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) - // Update the existing context to include the miniTocItems from GraphQL - automatedPageContext.miniTocItems.push(...changelogMiniTocItems) - - return { - props: { - mainContext: await getMainContext(req, res), - automatedPageContext, - schema, - }, - } -} +export { default, getServerSideProps } from '../../../../src/graphql/pages/breaking-changes' diff --git a/pages/[versionId]/graphql/overview/changelog.tsx b/pages/[versionId]/graphql/overview/changelog.tsx index eef79a5c56..5f2f4e4665 100644 --- a/pages/[versionId]/graphql/overview/changelog.tsx +++ b/pages/[versionId]/graphql/overview/changelog.tsx @@ -1,77 +1 @@ -import { GetServerSideProps } from 'next' -import React from 'react' - -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' -import { AutomatedPage } from 'components/article/AutomatedPage' -import { - AutomatedPageContext, - AutomatedPageContextT, - getAutomatedPageContextFromRequest, -} from 'components/context/AutomatedPageContext' -import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js' -import { Changelog } from 'components/graphql/Changelog' -import { ChangelogItemT } from 'components/graphql/types' -import { getGraphqlChangelog } from 'src/graphql/lib/index.js' - -type Props = { - mainContext: MainContextT - schema: ChangelogItemT[] - automatedPageContext: AutomatedPageContextT -} - -export default function GraphqlChangelog({ mainContext, schema, automatedPageContext }: Props) { - const content = - return ( - - - {content} - - - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as any - const res = context.res as any - const currentVersion = context.query.versionId as string - const schema = getGraphqlChangelog(currentVersion) as ChangelogItemT[] - if (!schema) throw new Error('No graphql free-pro-team changelog schema found.') - // Gets the miniTocItems in the article context. At this point it will only - // include miniTocItems that exist in Markdown pages in - // content/graphql/reference/* - const automatedPageContext = getAutomatedPageContextFromRequest(req) - const titles = schema.map((item) => `Schema changes for ${item.date}`) - const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) - // Update the existing context to include the miniTocItems from GraphQL - automatedPageContext.miniTocItems.push(...changelogMiniTocItems) - - // All groups in the schema have a change.changes array of strings that are - // all the HTML output from a Markdown conversion. E.g. - // `

Field filename was added to object type IssueTemplate

` - // Change these to just be the inside of the

tag. - // `Field filename was added to object type IssueTemplate` - // This makes the serialized state data smaller and it makes it possible - // to render it as... - // - //

  • Field filename was added to object type IssueTemplate
  • - // - // ...without the additional

    . - schema.forEach((item) => { - for (const group of [item.schemaChanges, item.previewChanges, item.upcomingChanges]) { - group.forEach((change) => { - change.changes = change.changes.map((html) => { - if (html.startsWith('

    ') && html.endsWith('

    ')) return html.slice(3, -4) - return html - }) - }) - } - }) - - return { - props: { - mainContext: await getMainContext(req, res), - automatedPageContext, - schema, - }, - } -} +export { default, getServerSideProps } from '../../../../src/graphql/pages/changelog' diff --git a/pages/[versionId]/graphql/overview/explorer.tsx b/pages/[versionId]/graphql/overview/explorer.tsx index 900d3ac964..73213a447c 100644 --- a/pages/[versionId]/graphql/overview/explorer.tsx +++ b/pages/[versionId]/graphql/overview/explorer.tsx @@ -1,59 +1 @@ -import { GetServerSideProps } from 'next' - -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' -import { DefaultLayout } from 'components/DefaultLayout' -import { useEffect, useRef } from 'react' - -type Props = { - mainContext: MainContextT - graphqlExplorerUrl: string -} -export default function GQLExplorer({ mainContext, graphqlExplorerUrl }: Props) { - const { page } = mainContext - const graphiqlRef = useRef(null) - - useEffect(() => { - if (typeof window !== 'undefined' && window.location.search) { - graphiqlRef.current?.contentWindow?.postMessage(window.location.search, graphqlExplorerUrl) - } - }, []) - - return ( - - -
    -

    {page.title}

    -
    - -
    - {/* eslint-disable-next-line jsx-a11y/iframe-has-title */} - -
    -
    -
    - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as any - const res = context.res as any - const graphqlExplorerUrl = - process.env.NODE_ENV === 'production' - ? 'https://graphql.github.com/explorer' - : 'http://localhost:3000' - - return { - props: { - mainContext: await getMainContext(req, res), - graphqlExplorerUrl, - }, - } -} +export { default, getServerSideProps } from '../../../../src/graphql/pages/explorer' diff --git a/pages/[versionId]/graphql/overview/schema-previews.tsx b/pages/[versionId]/graphql/overview/schema-previews.tsx index 31af42ea33..b8e4a276ba 100644 --- a/pages/[versionId]/graphql/overview/schema-previews.tsx +++ b/pages/[versionId]/graphql/overview/schema-previews.tsx @@ -1,56 +1 @@ -import { GetServerSideProps } from 'next' -import React from 'react' - -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' -import { AutomatedPage } from 'components/article/AutomatedPage' -import { - AutomatedPageContext, - AutomatedPageContextT, - getAutomatedPageContextFromRequest, -} from 'components/context/AutomatedPageContext' -import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js' -import { Previews } from 'components/graphql/Previews' -import { PreviewT } from 'components/graphql/types' -import { getPreviews } from 'src/graphql/lib/index.js' - -type Props = { - mainContext: MainContextT - schema: PreviewT[] - automatedPageContext: AutomatedPageContextT -} - -export default function GraphqlPreviews({ mainContext, schema, automatedPageContext }: Props) { - const content = - return ( - - - {content} - - - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as any - const res = context.res as any - const currentVersion = context.query.versionId as string - const schema = getPreviews(currentVersion) as PreviewT[] - if (!schema) throw new Error(`No graphql preview schema found for ${currentVersion}`) - - // Gets the miniTocItems in the article context. At this point it will only - // include miniTocItems that exist in Markdown pages in - // content/graphql/reference/* - const automatedPageContext = getAutomatedPageContextFromRequest(req) - const titles = schema.map((item) => item.title) - const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) - // Update the existing context to include the miniTocItems from GraphQL - automatedPageContext.miniTocItems.push(...changelogMiniTocItems) - - return { - props: { - mainContext: await getMainContext(req, res), - automatedPageContext, - schema, - }, - } -} +export { default, getServerSideProps } from '../../../../src/graphql/pages/schema-previews' diff --git a/pages/[versionId]/graphql/reference/[page].tsx b/pages/[versionId]/graphql/reference/[page].tsx index 03beda7657..dccce0768c 100644 --- a/pages/[versionId]/graphql/reference/[page].tsx +++ b/pages/[versionId]/graphql/reference/[page].tsx @@ -1,77 +1 @@ -import { GetServerSideProps } from 'next' -import React from 'react' - -import { GraphqlPage } from 'components/graphql/GraphqlPage' -import { getGraphqlSchema, getMiniToc } from 'src/graphql/lib/index.js' -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' -import type { ObjectT, GraphqlT } from 'components/graphql/types' -import { AutomatedPage } from 'components/article/AutomatedPage' -import { - AutomatedPageContext, - AutomatedPageContextT, - getAutomatedPageContextFromRequest, -} from 'components/context/AutomatedPageContext' - -type Props = { - mainContext: MainContextT - automatedPageContext: AutomatedPageContextT - schema: Object - language: string - graphqlPageName: string - objects?: ObjectT[] -} - -export default function GraphqlReferencePage({ - mainContext, - automatedPageContext, - schema, - graphqlPageName, - objects, -}: Props) { - const content = ( - - ) - return ( - - - {content} - - - ) -} - -export const getServerSideProps: GetServerSideProps = async (context) => { - const req = context.req as any - const res = context.res as any - const language = req.context.currentLanguage as string - const currentVersion = req.context.currentVersion as string - const page = context.query.page as string - const graphqlPageName = page === 'input-objects' ? 'inputObjects' : page - - const schema = getGraphqlSchema(currentVersion, graphqlPageName) - // When the page is 'interfaces', we need to make another call to - // get the objects page properties too. - const objects = - graphqlPageName === 'interfaces' ? getGraphqlSchema(currentVersion, 'objects') : null - - // Gets the miniTocItems in the article context. At this point it will only - // include miniTocItems that exist in Markdown pages in - // content/graphql/reference/* - const automatedPageContext = getAutomatedPageContextFromRequest(req) - - const items = schema.map((item: GraphqlT) => item.name) - const graphqlMiniTocItems = await getMiniToc(req.context, graphqlPageName, items) - // Update the existing context to include the miniTocItems from GraphQL - automatedPageContext.miniTocItems.push(...graphqlMiniTocItems) - - return { - props: { - mainContext: await getMainContext(req, res), - automatedPageContext, - schema, - language, - graphqlPageName, - objects, - }, - } -} +export { default, getServerSideProps } from '../../../../src/graphql/pages/reference' diff --git a/components/graphql/BreakingChanges.tsx b/src/graphql/components/BreakingChanges.tsx similarity index 96% rename from components/graphql/BreakingChanges.tsx rename to src/graphql/components/BreakingChanges.tsx index 10848b7e6e..1019010330 100644 --- a/components/graphql/BreakingChanges.tsx +++ b/src/graphql/components/BreakingChanges.tsx @@ -2,7 +2,7 @@ import React from 'react' import cx from 'classnames' import { HeadingLink } from 'components/article/HeadingLink' -import { BreakingChangesT } from 'components/graphql/types' +import { BreakingChangesT } from './types' import styles from 'components/ui/MarkdownContent/MarkdownContent.module.scss' type Props = { diff --git a/components/graphql/Changelog.tsx b/src/graphql/components/Changelog.tsx similarity index 96% rename from components/graphql/Changelog.tsx rename to src/graphql/components/Changelog.tsx index ffe4f3587b..fa9cfcdf75 100644 --- a/components/graphql/Changelog.tsx +++ b/src/graphql/components/Changelog.tsx @@ -2,7 +2,7 @@ import React from 'react' import cx from 'classnames' import { HeadingLink } from 'components/article/HeadingLink' -import { ChangelogItemT } from 'components/graphql/types' +import { ChangelogItemT } from './types' import styles from 'components/ui/MarkdownContent/MarkdownContent.module.scss' type Props = { diff --git a/components/graphql/Enum.tsx b/src/graphql/components/Enum.tsx similarity index 100% rename from components/graphql/Enum.tsx rename to src/graphql/components/Enum.tsx diff --git a/components/graphql/GraphqlItem.tsx b/src/graphql/components/GraphqlItem.tsx similarity index 100% rename from components/graphql/GraphqlItem.tsx rename to src/graphql/components/GraphqlItem.tsx diff --git a/components/graphql/GraphqlPage.tsx b/src/graphql/components/GraphqlPage.tsx similarity index 82% rename from components/graphql/GraphqlPage.tsx rename to src/graphql/components/GraphqlPage.tsx index f9a29977ff..f6e5503f17 100644 --- a/components/graphql/GraphqlPage.tsx +++ b/src/graphql/components/GraphqlPage.tsx @@ -1,14 +1,14 @@ import React from 'react' import cx from 'classnames' -import { Enum } from 'components/graphql/Enum' -import { InputObject } from 'components/graphql/InputObject' -import { Interface } from 'components/graphql/Interface' -import { Scalar } from 'components/graphql/Scalar' -import { Mutation } from 'components/graphql/Mutation' -import { Object } from 'components/graphql/Object' -import { Query } from 'components/graphql/Query' -import { Union } from 'components/graphql/Union' +import { Enum } from './Enum' +import { InputObject } from './InputObject' +import { Interface } from './Interface' +import { Scalar } from './Scalar' +import { Mutation } from './Mutation' +import { Object } from './Object' +import { Query } from './Query' +import { Union } from './Union' import type { EnumT, InputObjectT, @@ -18,7 +18,7 @@ import type { QueryT, ScalarT, UnionT, -} from 'components/graphql/types' +} from './types' import styles from 'components/ui/MarkdownContent/MarkdownContent.module.scss' type Props = { diff --git a/components/graphql/InputObject.tsx b/src/graphql/components/InputObject.tsx similarity index 100% rename from components/graphql/InputObject.tsx rename to src/graphql/components/InputObject.tsx diff --git a/components/graphql/Interface.tsx b/src/graphql/components/Interface.tsx similarity index 100% rename from components/graphql/Interface.tsx rename to src/graphql/components/Interface.tsx diff --git a/components/graphql/Mutation.tsx b/src/graphql/components/Mutation.tsx similarity index 100% rename from components/graphql/Mutation.tsx rename to src/graphql/components/Mutation.tsx diff --git a/components/graphql/Notice.tsx b/src/graphql/components/Notice.tsx similarity index 100% rename from components/graphql/Notice.tsx rename to src/graphql/components/Notice.tsx diff --git a/components/graphql/Object.tsx b/src/graphql/components/Object.tsx similarity index 100% rename from components/graphql/Object.tsx rename to src/graphql/components/Object.tsx diff --git a/components/graphql/Previews.tsx b/src/graphql/components/Previews.tsx similarity index 96% rename from components/graphql/Previews.tsx rename to src/graphql/components/Previews.tsx index 368bfe2b66..2e59393ecc 100644 --- a/components/graphql/Previews.tsx +++ b/src/graphql/components/Previews.tsx @@ -4,7 +4,7 @@ import cx from 'classnames' import { HeadingLink } from 'components/article/HeadingLink' import { useTranslation } from 'components/hooks/useTranslation' -import { PreviewT } from 'components/graphql/types' +import { PreviewT } from './types' import styles from 'components/ui/MarkdownContent/MarkdownContent.module.scss' type Props = { diff --git a/components/graphql/Query.tsx b/src/graphql/components/Query.tsx similarity index 100% rename from components/graphql/Query.tsx rename to src/graphql/components/Query.tsx diff --git a/components/graphql/Scalar.tsx b/src/graphql/components/Scalar.tsx similarity index 100% rename from components/graphql/Scalar.tsx rename to src/graphql/components/Scalar.tsx diff --git a/components/graphql/Table.tsx b/src/graphql/components/Table.tsx similarity index 100% rename from components/graphql/Table.tsx rename to src/graphql/components/Table.tsx diff --git a/components/graphql/Union.tsx b/src/graphql/components/Union.tsx similarity index 100% rename from components/graphql/Union.tsx rename to src/graphql/components/Union.tsx diff --git a/components/graphql/types.tsx b/src/graphql/components/types.tsx similarity index 100% rename from components/graphql/types.tsx rename to src/graphql/components/types.tsx diff --git a/src/graphql/pages/breaking-changes.tsx b/src/graphql/pages/breaking-changes.tsx new file mode 100644 index 0000000000..3620cbaad8 --- /dev/null +++ b/src/graphql/pages/breaking-changes.tsx @@ -0,0 +1,62 @@ +import { GetServerSideProps } from 'next' +import React from 'react' + +import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' +import { AutomatedPage } from 'components/article/AutomatedPage' +import { + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' +import { BreakingChanges } from 'src/graphql/components/BreakingChanges' +import { BreakingChangesT } from 'src/graphql/components/types' + +type Props = { + mainContext: MainContextT + schema: BreakingChangesT + automatedPageContext: AutomatedPageContextT +} + +export default function GraphqlBreakingChanges({ + mainContext, + schema, + automatedPageContext, +}: Props) { + return ( + + + + + + + + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { getGraphqlBreakingChanges } = await import('src/graphql/lib/index.js') + const { getAutomatedPageMiniTocItems } = await import('lib/get-mini-toc-items.js') + + const req = context.req as any + const res = context.res as any + const currentVersion = context.query.versionId as string + const schema = getGraphqlBreakingChanges(currentVersion) + if (!schema) throw new Error(`No graphql breaking changes schema found for ${currentVersion}`) + + // Gets the miniTocItems in the article context. At this point it will only + // include miniTocItems that exist in Markdown pages in + // content/graphql/reference/* + const automatedPageContext = getAutomatedPageContextFromRequest(req) + const titles = Object.keys(schema).map((item) => `Changes scheduled for ${item}`) + const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) + // Update the existing context to include the miniTocItems from GraphQL + automatedPageContext.miniTocItems.push(...changelogMiniTocItems) + + return { + props: { + mainContext: await getMainContext(req, res), + automatedPageContext, + schema, + }, + } +} diff --git a/src/graphql/pages/changelog.tsx b/src/graphql/pages/changelog.tsx new file mode 100644 index 0000000000..f5f85e5ecb --- /dev/null +++ b/src/graphql/pages/changelog.tsx @@ -0,0 +1,78 @@ +import { GetServerSideProps } from 'next' +import React from 'react' + +import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' +import { AutomatedPage } from 'components/article/AutomatedPage' +import { + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' +import { Changelog } from 'src/graphql/components/Changelog' +import { ChangelogItemT } from 'src/graphql/components/types' + +type Props = { + mainContext: MainContextT + schema: ChangelogItemT[] + automatedPageContext: AutomatedPageContextT +} + +export default function GraphqlChangelog({ mainContext, schema, automatedPageContext }: Props) { + const content = + return ( + + + {content} + + + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { getGraphqlChangelog } = await import('src/graphql/lib/index.js') + const { getAutomatedPageMiniTocItems } = await import('lib/get-mini-toc-items.js') + + const req = context.req as any + const res = context.res as any + const currentVersion = context.query.versionId as string + const schema = getGraphqlChangelog(currentVersion) as ChangelogItemT[] + if (!schema) throw new Error('No graphql free-pro-team changelog schema found.') + // Gets the miniTocItems in the article context. At this point it will only + // include miniTocItems that exist in Markdown pages in + // content/graphql/reference/* + const automatedPageContext = getAutomatedPageContextFromRequest(req) + const titles = schema.map((item) => `Schema changes for ${item.date}`) + const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) + // Update the existing context to include the miniTocItems from GraphQL + automatedPageContext.miniTocItems.push(...changelogMiniTocItems) + + // All groups in the schema have a change.changes array of strings that are + // all the HTML output from a Markdown conversion. E.g. + // `

    Field filename was added to object type IssueTemplate

    ` + // Change these to just be the inside of the

    tag. + // `Field filename was added to object type IssueTemplate` + // This makes the serialized state data smaller and it makes it possible + // to render it as... + // + //

  • Field filename was added to object type IssueTemplate
  • + // + // ...without the additional

    . + schema.forEach((item) => { + for (const group of [item.schemaChanges, item.previewChanges, item.upcomingChanges]) { + group.forEach((change) => { + change.changes = change.changes.map((html) => { + if (html.startsWith('

    ') && html.endsWith('

    ')) return html.slice(3, -4) + return html + }) + }) + } + }) + + return { + props: { + mainContext: await getMainContext(req, res), + automatedPageContext, + schema, + }, + } +} diff --git a/src/graphql/pages/explorer.tsx b/src/graphql/pages/explorer.tsx new file mode 100644 index 0000000000..900d3ac964 --- /dev/null +++ b/src/graphql/pages/explorer.tsx @@ -0,0 +1,59 @@ +import { GetServerSideProps } from 'next' + +import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' +import { DefaultLayout } from 'components/DefaultLayout' +import { useEffect, useRef } from 'react' + +type Props = { + mainContext: MainContextT + graphqlExplorerUrl: string +} +export default function GQLExplorer({ mainContext, graphqlExplorerUrl }: Props) { + const { page } = mainContext + const graphiqlRef = useRef(null) + + useEffect(() => { + if (typeof window !== 'undefined' && window.location.search) { + graphiqlRef.current?.contentWindow?.postMessage(window.location.search, graphqlExplorerUrl) + } + }, []) + + return ( + + +
    +

    {page.title}

    +
    + +
    + {/* eslint-disable-next-line jsx-a11y/iframe-has-title */} + +
    +
    +
    + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const req = context.req as any + const res = context.res as any + const graphqlExplorerUrl = + process.env.NODE_ENV === 'production' + ? 'https://graphql.github.com/explorer' + : 'http://localhost:3000' + + return { + props: { + mainContext: await getMainContext(req, res), + graphqlExplorerUrl, + }, + } +} diff --git a/src/graphql/pages/reference.tsx b/src/graphql/pages/reference.tsx new file mode 100644 index 0000000000..8bcf878470 --- /dev/null +++ b/src/graphql/pages/reference.tsx @@ -0,0 +1,78 @@ +import { GetServerSideProps } from 'next' +import React from 'react' + +import { GraphqlPage } from 'src/graphql/components/GraphqlPage' +import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' +import type { ObjectT, GraphqlT } from 'src/graphql/components/types' +import { AutomatedPage } from 'components/article/AutomatedPage' +import { + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' + +type Props = { + mainContext: MainContextT + automatedPageContext: AutomatedPageContextT + schema: Object + language: string + graphqlPageName: string + objects?: ObjectT[] +} + +export default function GraphqlReferencePage({ + mainContext, + automatedPageContext, + schema, + graphqlPageName, + objects, +}: Props) { + const content = ( + + ) + return ( + + + {content} + + + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { getGraphqlSchema, getMiniToc } = await import('src/graphql/lib/index.js') + + const req = context.req as any + const res = context.res as any + const language = req.context.currentLanguage as string + const currentVersion = req.context.currentVersion as string + const page = context.query.page as string + const graphqlPageName = page === 'input-objects' ? 'inputObjects' : page + + const schema = getGraphqlSchema(currentVersion, graphqlPageName) + // When the page is 'interfaces', we need to make another call to + // get the objects page properties too. + const objects = + graphqlPageName === 'interfaces' ? getGraphqlSchema(currentVersion, 'objects') : null + + // Gets the miniTocItems in the article context. At this point it will only + // include miniTocItems that exist in Markdown pages in + // content/graphql/reference/* + const automatedPageContext = getAutomatedPageContextFromRequest(req) + + const items = schema.map((item: GraphqlT) => item.name) + const graphqlMiniTocItems = await getMiniToc(req.context, graphqlPageName, items) + // Update the existing context to include the miniTocItems from GraphQL + automatedPageContext.miniTocItems.push(...graphqlMiniTocItems) + + return { + props: { + mainContext: await getMainContext(req, res), + automatedPageContext, + schema, + language, + graphqlPageName, + objects, + }, + } +} diff --git a/src/graphql/pages/schema-previews.tsx b/src/graphql/pages/schema-previews.tsx new file mode 100644 index 0000000000..08e1888b89 --- /dev/null +++ b/src/graphql/pages/schema-previews.tsx @@ -0,0 +1,57 @@ +import { GetServerSideProps } from 'next' +import React from 'react' + +import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' +import { AutomatedPage } from 'components/article/AutomatedPage' +import { + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' +import { Previews } from 'src/graphql/components/Previews' +import { PreviewT } from 'src/graphql/components/types' + +type Props = { + mainContext: MainContextT + schema: PreviewT[] + automatedPageContext: AutomatedPageContextT +} + +export default function GraphqlPreviews({ mainContext, schema, automatedPageContext }: Props) { + const content = + return ( + + + {content} + + + ) +} + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { getPreviews } = await import('src/graphql/lib/index.js') + const { getAutomatedPageMiniTocItems } = await import('lib/get-mini-toc-items.js') + + const req = context.req as any + const res = context.res as any + const currentVersion = context.query.versionId as string + const schema = getPreviews(currentVersion) as PreviewT[] + if (!schema) throw new Error(`No graphql preview schema found for ${currentVersion}`) + + // Gets the miniTocItems in the article context. At this point it will only + // include miniTocItems that exist in Markdown pages in + // content/graphql/reference/* + const automatedPageContext = getAutomatedPageContextFromRequest(req) + const titles = schema.map((item) => item.title) + const changelogMiniTocItems = await getAutomatedPageMiniTocItems(titles, req.context.context, 2) + // Update the existing context to include the miniTocItems from GraphQL + automatedPageContext.miniTocItems.push(...changelogMiniTocItems) + + return { + props: { + mainContext: await getMainContext(req, res), + automatedPageContext, + schema, + }, + } +}