Merge branch 'main' into repo-sync
This commit is contained in:
@@ -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 (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>
|
||||
<BreakingChanges schema={schema} />
|
||||
</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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'
|
||||
|
||||
@@ -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 = <Changelog changelogItems={schema} />
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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.
|
||||
// `<p>Field filename was added to object type <code>IssueTemplate</code></p>`
|
||||
// Change these to just be the inside of the <p> tag.
|
||||
// `Field filename was added to object type <code>IssueTemplate</code>`
|
||||
// This makes the serialized state data smaller and it makes it possible
|
||||
// to render it as...
|
||||
//
|
||||
// <li>Field filename was added to object type <code>IssueTemplate</code></li>
|
||||
//
|
||||
// ...without the additional <p>.
|
||||
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('<p>') && html.endsWith('</p>')) return html.slice(3, -4)
|
||||
return html
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
props: {
|
||||
mainContext: await getMainContext(req, res),
|
||||
automatedPageContext,
|
||||
schema,
|
||||
},
|
||||
}
|
||||
}
|
||||
export { default, getServerSideProps } from '../../../../src/graphql/pages/changelog'
|
||||
|
||||
@@ -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<HTMLIFrameElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && window.location.search) {
|
||||
graphiqlRef.current?.contentWindow?.postMessage(window.location.search, graphqlExplorerUrl)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<DefaultLayout>
|
||||
<div className="container-xl px-3 px-md-6 my-4 my-lg-4">
|
||||
<h1 id="title-h1">{page.title}</h1>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{/* eslint-disable-next-line jsx-a11y/iframe-has-title */}
|
||||
<iframe
|
||||
ref={graphiqlRef}
|
||||
style={{ height: 715 }}
|
||||
className="border width-full"
|
||||
scrolling="no"
|
||||
src={graphqlExplorerUrl}
|
||||
>
|
||||
<p>You must have iframes enabled to use this feature.</p>
|
||||
</iframe>
|
||||
</div>
|
||||
</DefaultLayout>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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'
|
||||
|
||||
@@ -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 = <Previews schema={schema} />
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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'
|
||||
|
||||
@@ -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 = (
|
||||
<GraphqlPage schema={schema} pageName={graphqlPageName} objects={objects || undefined} />
|
||||
)
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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'
|
||||
|
||||
@@ -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 = {
|
||||
@@ -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 = {
|
||||
@@ -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 = {
|
||||
@@ -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 = {
|
||||
62
src/graphql/pages/breaking-changes.tsx
Normal file
62
src/graphql/pages/breaking-changes.tsx
Normal file
@@ -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 (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>
|
||||
<BreakingChanges schema={schema} />
|
||||
</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
78
src/graphql/pages/changelog.tsx
Normal file
78
src/graphql/pages/changelog.tsx
Normal file
@@ -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 = <Changelog changelogItems={schema} />
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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.
|
||||
// `<p>Field filename was added to object type <code>IssueTemplate</code></p>`
|
||||
// Change these to just be the inside of the <p> tag.
|
||||
// `Field filename was added to object type <code>IssueTemplate</code>`
|
||||
// This makes the serialized state data smaller and it makes it possible
|
||||
// to render it as...
|
||||
//
|
||||
// <li>Field filename was added to object type <code>IssueTemplate</code></li>
|
||||
//
|
||||
// ...without the additional <p>.
|
||||
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('<p>') && html.endsWith('</p>')) return html.slice(3, -4)
|
||||
return html
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
props: {
|
||||
mainContext: await getMainContext(req, res),
|
||||
automatedPageContext,
|
||||
schema,
|
||||
},
|
||||
}
|
||||
}
|
||||
59
src/graphql/pages/explorer.tsx
Normal file
59
src/graphql/pages/explorer.tsx
Normal file
@@ -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<HTMLIFrameElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && window.location.search) {
|
||||
graphiqlRef.current?.contentWindow?.postMessage(window.location.search, graphqlExplorerUrl)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<DefaultLayout>
|
||||
<div className="container-xl px-3 px-md-6 my-4 my-lg-4">
|
||||
<h1 id="title-h1">{page.title}</h1>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{/* eslint-disable-next-line jsx-a11y/iframe-has-title */}
|
||||
<iframe
|
||||
ref={graphiqlRef}
|
||||
style={{ height: 715 }}
|
||||
className="border width-full"
|
||||
scrolling="no"
|
||||
src={graphqlExplorerUrl}
|
||||
>
|
||||
<p>You must have iframes enabled to use this feature.</p>
|
||||
</iframe>
|
||||
</div>
|
||||
</DefaultLayout>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
78
src/graphql/pages/reference.tsx
Normal file
78
src/graphql/pages/reference.tsx
Normal file
@@ -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 = (
|
||||
<GraphqlPage schema={schema} pageName={graphqlPageName} objects={objects || undefined} />
|
||||
)
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
57
src/graphql/pages/schema-previews.tsx
Normal file
57
src/graphql/pages/schema-previews.tsx
Normal file
@@ -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 = <Previews schema={schema} />
|
||||
return (
|
||||
<MainContext.Provider value={mainContext}>
|
||||
<AutomatedPageContext.Provider value={automatedPageContext}>
|
||||
<AutomatedPage>{content}</AutomatedPage>
|
||||
</AutomatedPageContext.Provider>
|
||||
</MainContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<Props> = 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user