Skip to content

Commit fe84824

Browse files
authored
Restructure GraphQL automated content scripts (github#34308)
1 parent b66f4e7 commit fe84824

38 files changed

+62
-62
lines changed

.github/workflows/triage-unallowed-contributions.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
- 'assets/fonts/**'
1515
- 'data/graphql/**'
1616
- 'Dockerfile*'
17-
- 'lib/graphql/**'
17+
- 'src/**'
1818
- 'lib/redirects/**'
1919
- 'lib/rest/**'
2020
- 'lib/webhooks/**'
@@ -58,7 +58,7 @@ jobs:
5858
- 'assets/fonts/**'
5959
- 'data/graphql/**'
6060
- 'Dockerfile*'
61-
- 'lib/graphql/**'
61+
- 'src/**'
6262
- 'lib/redirects/**'
6363
- 'lib/rest/**'
6464
- 'lib/webhooks/**'
@@ -81,9 +81,9 @@ jobs:
8181
'assets/fonts/**',
8282
'data/graphql/**',
8383
'Dockerfile*',
84-
'lib/graphql/**',
84+
'src/**',
8585
'lib/redirects/**',
86-
'lib/rest/**',
86+
'lib/rest/**',
8787
'lib/webhooks/**',
8888
'package*.json',
8989
'scripts/**',

.github/workflows/update-graphql-files.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
# need to use a token from a user with access to github/github for this step
4040
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_FR }}
4141
run: |
42-
script/graphql/update-files.js
42+
src/graphql/scripts/update-files.js
4343
- name: Create pull request
4444
id: create-pull-request
4545
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ COPY stylesheets ./stylesheets
4848
COPY pages ./pages
4949
COPY components ./components
5050
COPY lib ./lib
51+
COPY src ./src
5152
# Certain content is necessary for being able to build
5253
COPY content/index.md ./content/index.md
5354
COPY content/rest ./content/rest
@@ -88,6 +89,7 @@ COPY --chown=node:node package.json ./
8889
COPY --chown=node:node assets ./assets
8990
COPY --chown=node:node content ./content
9091
COPY --chown=node:node lib ./lib
92+
COPY --chown=node:node src ./src
9193
COPY --chown=node:node middleware ./middleware
9294
COPY --chown=node:node data ./data
9395
COPY --chown=node:node next.config.js ./

content/graphql/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
The `/content/graphql` directory is where the GitHub GraphQL API docs live!
44

55
* The `/content/graphql/guides` and `/content/graphql/overview` directories contain articles that are human-editable.
6-
* The `/content/graphql/reference` directory contains an article for each GraphQL data type used in the GitHub GraphQL API. Most of the content in this directory is rendered using `include` tags.
6+
* The `/content/graphql/reference` directory contains an article for each GraphQL data type used in the GitHub GraphQL API. This content is generated from the data in `src/graphql/data` and should not be edited by a human. **As a result, we cannot accept contributions to GraphQL API reference content in this repository.**
77

8-
The content rendered by `include` tags is sourced from the `/lib/graphql/static` directory, which is automatically generated from the API source code internally in GitHub, and should not be edited by a human. For more information, see the [`/lib/graphql/README.md`](/lib/graphql/README.md).
9-
10-
**As a result, we cannot accept contributions to GraphQL API reference content in this repository.**
8+
For more information, see the [`/src/graphql/README.md`](/src/graphql/README.md).

data/graphql/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GraphQL
22

33
The files in this directory are kept in sync with their counterparts on `github/github`
4-
by [automation](../script/graphql/README.md). These files **should not** be edited by humans.
4+
by [automation](../src/graphql/README.md). These files **should not** be edited by humans.
55

66
Dotcom source files:
77
```

pages/[versionId]/graphql/overview/breaking-changes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js'
1212
import { BreakingChanges } from 'components/graphql/BreakingChanges'
1313
import { BreakingChangesT } from 'components/graphql/types'
14-
import { getGraphqlBreakingChanges } from 'lib/graphql/index.js'
14+
import { getGraphqlBreakingChanges } from 'src/graphql/lib/index.js'
1515

1616
type Props = {
1717
mainContext: MainContextT

pages/[versionId]/graphql/overview/changelog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js'
1212
import { Changelog } from 'components/graphql/Changelog'
1313
import { ChangelogItemT } from 'components/graphql/types'
14-
import { getGraphqlChangelog } from 'lib/graphql/index.js'
14+
import { getGraphqlChangelog } from 'src/graphql/lib/index.js'
1515

1616
type Props = {
1717
mainContext: MainContextT

pages/[versionId]/graphql/overview/schema-previews.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { getAutomatedPageMiniTocItems } from 'lib/get-mini-toc-items.js'
1212
import { Previews } from 'components/graphql/Previews'
1313
import { PreviewT } from 'components/graphql/types'
14-
import { getPreviews } from 'lib/graphql/index.js'
14+
import { getPreviews } from 'src/graphql/lib/index.js'
1515

1616
type Props = {
1717
mainContext: MainContextT

pages/[versionId]/graphql/reference/[page].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GetServerSideProps } from 'next'
22
import React from 'react'
33

44
import { GraphqlPage } from 'components/graphql/GraphqlPage'
5-
import { getGraphqlSchema, getMiniToc } from 'lib/graphql/index.js'
5+
import { getGraphqlSchema, getMiniToc } from 'src/graphql/lib/index.js'
66
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
77
import type { ObjectT, GraphqlT } from 'components/graphql/types'
88
import { AutomatedPage } from 'components/article/AutomatedPage'

script/enterprise-server-deprecations/remove-static-files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { deprecated } from '../../lib/enterprise-server-releases.js'
1515

1616
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
1717
const webhooksStaticDir = path.join(process.cwd(), 'lib/webhooks/static')
18-
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
18+
const graphqlStaticDir = path.join(process.cwd(), 'src/graphql/data')
1919
const restDecoratedDir = path.join(process.cwd(), 'lib/rest/static/decorated')
2020
const ghesReleaseNotesDir = 'data/release-notes/enterprise-server'
2121

script/enterprise-server-releases/create-graphql-files.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { program } from 'commander'
1212
import mkdirp from 'mkdirp'
1313
import { allVersions } from '../../lib/all-versions.js'
1414

15-
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
15+
const graphqlStaticDir = path.join(process.cwd(), 'src/graphql/data')
1616
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
1717

1818
program
19-
.description('Create GraphQL files in lib/graphql/static based on an existing version.')
19+
.description('Create GraphQL files in src/graphql/data based on an existing version.')
2020
.option(
2121
'-n, --newVersion <version>',
2222
'The version to copy the files to. Must be in <plan@release> format.'

lib/graphql/README.md src/graphql/README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@
22

33
## About this directory
44

5-
* `lib/graphql/*.json` are human-editable.
6-
* `lib/graphql/static/*.json` are generated by [scripts](../script/graphql/README.md).
5+
* `src/graphql/lib` and `src/graphql/scripts` are human-editable.
6+
* `src/graphql/data/**` are generated by [scripts](../src/graphql/README.md).
77

88
## Editable files
99

10-
* `lib/graphql/validator.json`
10+
* `src/graphql/lib/validator.json`
1111
- JSON schema used in `tests/graphql.js`.
12-
* `lib/graphql/non-schema-scalars.json`
12+
* `src/graphql/lib/non-schema-scalars.json`
1313
- An array of scalar types that live in [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby/tree/356d9d369e444423bf06cab3dc767ec75fbc6745/lib/graphql/types) only. These are
1414
not part of the core GraphQL spec.
15-
* `lib/graphql/redirects.json`
16-
- A list of original `developer.github.com/v4` paths and their corresponding new `docs.github.com/graphql` paths. Used in redirect middleware and tests.
17-
* `lib/graphql/types.json`
15+
* `src/graphql/lib/types.json`
1816
- High-level GraphQL types and kinds.
1917

20-
## Static files
18+
## Data files
2119

22-
Generated by `script/graphql/update-files.js`:
20+
Generated by `src/graphql/scripts/update-files.js`:
2321

24-
* `lib/graphql/static/schema-VERSION.json` (separate files per version)
25-
* `lib/graphql/static/previews.json`
26-
* `lib/graphql/static/upcoming-changes.json`
27-
* `lib/graphql/static/changelog.json`
22+
* `src/graphql/data/schema-VERSION.json` (separate files per version)
23+
* `src/graphql/data/previews.json`
24+
* `src/graphql/data/upcoming-changes.json`
25+
* `src/graphql/data/changelog.json`
2826

2927
## Rendering docs
3028

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/graphql/index.js src/graphql/lib/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
readCompressedJsonFileFallbackLazily,
33
readCompressedJsonFileFallback,
4-
} from '../../lib/read-json-file.js'
5-
import { getAutomatedPageMiniTocItems } from '../get-mini-toc-items.js'
6-
import languages from '../languages.js'
7-
import { allVersions } from '../all-versions.js'
4+
} from '../../../lib/read-json-file.js'
5+
import { getAutomatedPageMiniTocItems } from '../../../lib/get-mini-toc-items.js'
6+
import languages from '../../../lib/languages.js'
7+
import { allVersions } from '../../../lib/all-versions.js'
88

99
/* ADD LANGUAGE KEY */
1010
let previews
@@ -22,7 +22,7 @@ export function getGraphqlSchema(version, type) {
2222
if (!graphqlSchema.has(graphqlVersion)) {
2323
graphqlSchema.set(
2424
graphqlVersion,
25-
readCompressedJsonFileFallback(`lib/graphql/static/schema-${graphqlVersion}.json`)
25+
readCompressedJsonFileFallback(`src/graphql/data/schema-${graphqlVersion}.json`)
2626
)
2727
}
2828
return graphqlSchema.get(graphqlVersion)[type]
@@ -32,7 +32,7 @@ export function getGraphqlChangelog() {
3232
if (!changelog.has('schema')) {
3333
changelog.set(
3434
'schema',
35-
readCompressedJsonFileFallbackLazily('./lib/graphql/static/changelog.json')()
35+
readCompressedJsonFileFallbackLazily('./src/graphql/data/changelog.json')()
3636
)
3737
}
3838

@@ -43,7 +43,7 @@ export function getGraphqlBreakingChanges(version) {
4343
const graphqlVersion = getGraphqlVersion(version)
4444
if (!upcomingChanges) {
4545
upcomingChanges = readCompressedJsonFileFallbackLazily(
46-
'./lib/graphql/static/upcoming-changes.json'
46+
'./src/graphql/data/upcoming-changes.json'
4747
)()
4848
}
4949
return upcomingChanges[graphqlVersion]
@@ -52,7 +52,7 @@ export function getGraphqlBreakingChanges(version) {
5252
export function getPreviews(version) {
5353
const graphqlVersion = getGraphqlVersion(version)
5454
if (!previews) {
55-
previews = readCompressedJsonFileFallbackLazily('./lib/graphql/static/previews.json')()
55+
previews = readCompressedJsonFileFallbackLazily('./src/graphql/data/previews.json')()
5656
}
5757
return previews[graphqlVersion]
5858
}
File renamed without changes.
File renamed without changes.

lib/graphql/validator.js src/graphql/lib/validator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// the tests in tests/graphql.js use this schema to ensure the integrity
2-
// of the data in lib/graphql/static/*.json
2+
// of the data in src/graphql/data/*.json
33

44
// PREVIEWS
55
export const previewsValidator = {

script/graphql/README.md src/graphql/scripts/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
A [scheduled workflow](../.github/workflows/update-graphql-files.yml) runs the following
44
scripts on a daily basis:
55
```
6-
script/graphql/update-files.js
6+
src/graphql/scripts/update-files.js
77
```
8-
These scripts update the [static JSON files](../../lib/graphql/static) used to
9-
render GraphQL docs. See the [`lib/graphql/README`](../../lib/graphql/README.md)
8+
These scripts update the [JSON data files](src/graphql/data) used to
9+
render GraphQL docs. See the [`src/graphql/README`](src/graphql/README.md)
1010
for more info.
1111

1212
**Note**: The changelog script pulls content from the internal-developer repo. It relies on graphql-docs automation running daily to update the changelog files in internal-developer.

script/graphql/build-changelog.js src/graphql/scripts/build-changelog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { diff, ChangeType } from '@graphql-inspector/core'
33
import { loadSchema } from '@graphql-tools/load'
44
import fs from 'fs'
5-
import renderContent from '../../lib/render-content/index.js'
5+
import renderContent from '../../../lib/render-content/index.js'
66

77
/**
88
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON

script/graphql/update-files.js src/graphql/scripts/update-files.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import path from 'path'
44
import mkdirp from 'mkdirp'
55
import yaml from 'js-yaml'
66
import { execSync } from 'child_process'
7-
import { getContents, listMatchingRefs } from '../helpers/git-utils.js'
8-
import { allVersions } from '../../lib/all-versions.js'
7+
import { getContents, listMatchingRefs } from '../../../script/helpers/git-utils.js'
8+
import { allVersions } from '../../../lib/all-versions.js'
99
import processPreviews from './utils/process-previews.js'
1010
import processUpcomingChanges from './utils/process-upcoming-changes.js'
1111
import processSchemas from './utils/process-schemas.js'
1212
import { prependDatedEntry, createChangelogEntry } from './build-changelog.js'
1313

1414
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
15-
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
15+
const graphqlStaticDir = path.join(process.cwd(), 'src/graphql/data')
1616
const dataFilenames = JSON.parse(
17-
await fs.readFile(path.join(process.cwd(), './script/graphql/utils/data-filenames.json'))
17+
await fs.readFile(path.join(process.cwd(), './src/graphql/scripts/utils/data-filenames.json'))
1818
)
1919

2020
// check for required PAT
@@ -75,7 +75,7 @@ async function main() {
7575
if (changelogEntry) {
7676
prependDatedEntry(
7777
changelogEntry,
78-
path.join(process.cwd(), 'lib/graphql/static/changelog.json')
78+
path.join(process.cwd(), 'src/graphql/data/changelog.json')
7979
)
8080
}
8181
}
@@ -104,7 +104,7 @@ async function getRemoteRawContent(filepath, graphqlVersion) {
104104
return getContents(...Object.values(options))
105105
}
106106

107-
// find the relevant filepath in script/graphql/utils/data-filenames.json
107+
// find the relevant filepath in src/graphql/scripts/util/data-filenames.json
108108
function getDataFilepath(id, graphqlVersion) {
109109
const versionType = getVersionType(graphqlVersion)
110110

script/graphql/utils/process-schemas.js src/graphql/scripts/utils/process-schemas.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fs from 'fs/promises'
66
import path from 'path'
77

88
const externalScalarsJSON = JSON.parse(
9-
await fs.readFile(path.join(process.cwd(), './lib/graphql/non-schema-scalars.json'))
9+
await fs.readFile(path.join(process.cwd(), './src/graphql/lib/non-schema-scalars.json'))
1010
)
1111
const externalScalars = await Promise.all(
1212
externalScalarsJSON.map(async (scalar) => {
@@ -18,7 +18,7 @@ const externalScalars = await Promise.all(
1818
)
1919

2020
// select and format all the data from the schema that we need for the docs
21-
// used in the build step by script/graphql/build-static-files.js
21+
// used in the build step
2222
export default async function processSchemas(idl, previewsPerVersion) {
2323
const schemaAST = parse(idl.toString())
2424
const schema = buildASTSchema(schemaAST)

script/graphql/utils/process-upcoming-changes.js src/graphql/scripts/utils/process-upcoming-changes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import yaml from 'js-yaml'
33
import { groupBy } from 'lodash-es'
4-
import renderContent from '../../../lib/render-content/index.js'
4+
import renderContent from '../../../../lib/render-content/index.js'
55

66
export default async function processUpcomingChanges(upcomingChangesYml) {
77
const upcomingChanges = yaml.load(upcomingChangesYml).upcoming_changes

script/graphql/utils/schema-helpers.js src/graphql/scripts/utils/schema-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
2-
import renderContent from '../../../lib/render-content/index.js'
2+
import renderContent from '../../../../lib/render-content/index.js'
33
import fs from 'fs/promises'
44
import graphql from 'graphql'
55
import path from 'path'
66

77
const graphqlTypes = JSON.parse(
8-
await fs.readFile(path.join(process.cwd(), './lib/graphql/types.json'))
8+
await fs.readFile(path.join(process.cwd(), './src/graphql/lib/types.json'))
99
)
1010
const { isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType } =
1111
graphql

tests/content/graphql.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import {
33
schemaValidator,
44
previewsValidator,
55
upcomingChangesValidator,
6-
} from '../../lib/graphql/validator.js'
6+
} from '../../src/graphql/lib/validator.js'
77
import revalidator from 'revalidator'
88
import { allVersions } from '../../lib/all-versions.js'
99
import { jest } from '@jest/globals'
1010

11-
const previewsJson = readJsonFile('./lib/graphql/static/previews.json')
12-
const upcomingChangesJson = readJsonFile('./lib/graphql/static/upcoming-changes.json')
11+
const previewsJson = readJsonFile('./src/graphql/data/previews.json')
12+
const upcomingChangesJson = readJsonFile('./src/graphql/data/upcoming-changes.json')
1313
const allVersionValues = Object.values(allVersions)
1414
const graphqlVersions = allVersionValues.map((v) => v.miscVersionName)
15-
const graphqlTypes = readJsonFile('./lib/graphql/types.json').map((t) => t.kind)
15+
const graphqlTypes = readJsonFile('./src/graphql/lib/types.json').map((t) => t.kind)
1616

1717
describe('graphql json files', () => {
1818
jest.setTimeout(3 * 60 * 1000)
@@ -30,7 +30,7 @@ describe('graphql json files', () => {
3030
// test up significantly.
3131
const typeObjsTested = new Set()
3232
graphqlVersions.forEach((version) => {
33-
const schemaJsonPerVersion = readJsonFile(`lib/graphql/static/schema-${version}.json`)
33+
const schemaJsonPerVersion = readJsonFile(`src/graphql/data/schema-${version}.json`)
3434
// all graphql types are arrays except for queries
3535
graphqlTypes.forEach((type) => {
3636
schemaJsonPerVersion[type].forEach((typeObj) => {

tests/graphql/build-changelog-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
cleanPreviewTitle,
55
previewAnchor,
66
prependDatedEntry,
7-
} from '../../script/graphql/build-changelog.js'
7+
} from '../../src/graphql/scripts/build-changelog.js'
88
import fs from 'fs/promises'
99
import MockDate from 'mockdate'
1010
import readJsonFile from '../../lib/read-json-file.js'

tests/unit/graphql.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import {
66
getGraphqlChangelog,
77
getGraphqlBreakingChanges,
88
getPreviews,
9-
} from '../../lib/graphql/index.js'
9+
} from '../../src/graphql/lib/index.js'
1010

1111
describe('graphql schema', () => {
12-
const graphqlTypes = JSON.parse(readFileSync('lib/graphql/types.json')).map((item) => item.kind)
12+
const graphqlTypes = JSON.parse(readFileSync('src/graphql/lib/types.json')).map(
13+
(item) => item.kind
14+
)
1315
for (const version in allVersions) {
1416
for (const type of graphqlTypes) {
1517
test(`getting the GraphQL ${type} schema works for ${version}`, async () => {

0 commit comments

Comments
 (0)