|
| 1 | +import React from 'react' |
| 2 | +import cx from 'classnames' |
| 3 | +import { LinkIcon } from '@primer/octicons-react' |
| 4 | + |
| 5 | +import { Enum } from 'components/graphql/Enum' |
| 6 | +import { InputObject } from 'components/graphql/InputObject' |
| 7 | +import { Interface } from 'components/graphql/Interface' |
| 8 | +import { Scalar } from 'components/graphql/Scalar' |
| 9 | +import { Mutation } from 'components/graphql/Mutation' |
| 10 | +import { Object } from 'components/graphql/Object' |
| 11 | +import { Query } from 'components/graphql/Query' |
| 12 | +import { Union } from 'components/graphql/Union' |
| 13 | +import type { |
| 14 | + EnumT, |
| 15 | + InputObjectT, |
| 16 | + InterfaceT, |
| 17 | + MutationT, |
| 18 | + ObjectT, |
| 19 | + QueryT, |
| 20 | + ScalarT, |
| 21 | + UnionT, |
| 22 | +} from 'components/graphql/types' |
| 23 | +import styles from 'components/ui/MarkdownContent/MarkdownContent.module.scss' |
| 24 | + |
| 25 | +type Props = { |
| 26 | + schema: Object |
| 27 | + pageName: string |
| 28 | + objects?: ObjectT[] |
| 29 | +} |
| 30 | + |
| 31 | +export const GraphqlPage = ({ schema, pageName, objects }: Props) => { |
| 32 | + const graphqlItems: JSX.Element[] = [] // In the case of the H2s for Queries |
| 33 | + |
| 34 | + // The queries page has two heading sections (connections and fields) |
| 35 | + // So we need to add the heading component and the children under it |
| 36 | + // for each section. |
| 37 | + if (pageName === 'queries') { |
| 38 | + graphqlItems.push( |
| 39 | + <h2 id="connections" key="query-connections-heading"> |
| 40 | + <a className="doctocat-link" href="#connections"> |
| 41 | + <LinkIcon className="octicon-link" size="small" /> |
| 42 | + </a> |
| 43 | + Connections |
| 44 | + </h2> |
| 45 | + ) |
| 46 | + graphqlItems.push( |
| 47 | + ...(schema as QueryT).connections.map((item) => ( |
| 48 | + <Query item={item} key={item.id + item.name} /> |
| 49 | + )) |
| 50 | + ) |
| 51 | + graphqlItems.push( |
| 52 | + <h2 id="fields" key="query-fields-heading"> |
| 53 | + <a className="doctocat-link" href="#fields"> |
| 54 | + <LinkIcon className="octicon-link" size="small" /> |
| 55 | + </a> |
| 56 | + Fields |
| 57 | + </h2> |
| 58 | + ) |
| 59 | + |
| 60 | + graphqlItems.push( |
| 61 | + ...(schema as QueryT).fields.map((item) => <Query item={item} key={item.id + item.name} />) |
| 62 | + ) |
| 63 | + } else if (pageName === 'enums') { |
| 64 | + graphqlItems.push( |
| 65 | + ...(schema as EnumT[]).map((item) => { |
| 66 | + return <Enum key={item.id} item={item} /> |
| 67 | + }) |
| 68 | + ) |
| 69 | + } else if (pageName === 'inputObjects') { |
| 70 | + graphqlItems.push( |
| 71 | + ...(schema as InputObjectT[]).map((item) => { |
| 72 | + return <InputObject key={item.id} item={item} /> |
| 73 | + }) |
| 74 | + ) |
| 75 | + } else if (pageName === 'interfaces' && objects) { |
| 76 | + graphqlItems.push( |
| 77 | + ...(schema as InterfaceT[]).map((item) => { |
| 78 | + return <Interface key={item.id} item={item} objects={objects} /> |
| 79 | + }) |
| 80 | + ) |
| 81 | + } else if (pageName === 'mutations') { |
| 82 | + graphqlItems.push( |
| 83 | + ...(schema as MutationT[]).map((item) => { |
| 84 | + return <Mutation key={item.id} item={item} /> |
| 85 | + }) |
| 86 | + ) |
| 87 | + } else if (pageName === 'objects') { |
| 88 | + graphqlItems.push( |
| 89 | + ...(schema as ObjectT[]).map((item) => { |
| 90 | + return <Object key={item.id} item={item} /> |
| 91 | + }) |
| 92 | + ) |
| 93 | + } else if (pageName === 'scalars') { |
| 94 | + graphqlItems.push( |
| 95 | + ...(schema as ScalarT[]).map((item) => { |
| 96 | + return <Scalar key={item.id} item={item} /> |
| 97 | + }) |
| 98 | + ) |
| 99 | + } else if (pageName === 'unions') { |
| 100 | + graphqlItems.push( |
| 101 | + ...(schema as UnionT[]).map((item) => { |
| 102 | + return <Union key={item.id} item={item} /> |
| 103 | + }) |
| 104 | + ) |
| 105 | + } |
| 106 | + |
| 107 | + return <div className={cx(styles.automatedPages, styles.markdownBody)}>{graphqlItems}</div> |
| 108 | +} |
0 commit comments