Skip to content

Commit 7b7ae0b

Browse files
committed
Add docs
1 parent 9d5af1f commit 7b7ae0b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

script/graphql/build-changelog.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ async function main() {
4343
}
4444
}
4545

46-
47-
// Compare `oldSchemaString` to `newSchemaString`, and if there are any
48-
// changes that warrant a changelog entry, return a changelog entry.
49-
// Otherwise, return null.
46+
/**
47+
* Compare `oldSchemaString` to `newSchemaString`, and if there are any
48+
* changes that warrant a changelog entry, return a changelog entry.
49+
* Based on the parsed `previews`, identify changes that are under a preview.
50+
* Otherwise, return null.
51+
* @param {string} [oldSchemaString]
52+
* @param {string} [newSchemaString]
53+
* @param {object} [previews]
54+
* @return {object?}
55+
*/
5056
async function createChangelogEntry(oldSchemaString, newSchemaString, previews) {
5157
// Create schema objects out of the strings
5258
const oldSchema = await loadSchema(oldSchemaString)
@@ -108,8 +114,12 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews)
108114
}
109115
}
110116

111-
// prepare the preview title from github/github source for the docs.
112-
// ported from build-changelog-from-markdown
117+
/**
118+
* Prepare the preview title from github/github source for the docs.
119+
* (ported from build-changelog-from-markdown)
120+
* @param {string} title
121+
* @return {string}
122+
*/
113123
function cleanPreviewTitle(title) {
114124
if (title == "UpdateRefsPreview") {
115125
title = "Update refs preview"
@@ -122,17 +132,23 @@ function cleanPreviewTitle(title) {
122132
}
123133

124134
/**
135+
* Turn the given title into an HTML-ready anchor.
136+
* (ported from https://github.com/github/graphql-docs/blob/master/lib/graphql_docs/update_internal_developer/change_log.rb#L281)
125137
* @param {string} [previewTitle]
126138
* @return {string}
127139
*/
128140
function previewAnchor(previewTitle) {
129-
// ported from https://github.com/github/graphql-docs/blob/master/lib/graphql_docs/update_internal_developer/change_log.rb#L281
130141
return previewTitle
131142
.toLowerCase()
132143
.replace(/ /g, '-')
133144
.replace(/[^\w-]/g, '')
134145
}
135146

147+
/**
148+
* Turn changes from graphql-inspector into messages for the HTML changelog.
149+
* @param {Array<object>} changes
150+
* @return {Array<string>}
151+
*/
136152
function cleanMessagesFromChanges(changes) {
137153
return changes.map(function (change) {
138154
// replace single quotes around graphql names with backticks,
@@ -141,6 +157,15 @@ function cleanMessagesFromChanges(changes) {
141157
})
142158
}
143159

160+
/**
161+
* Split `changesToReport` into two parts,
162+
* one for changes in the main schema,
163+
* and another for changes that are under preview.
164+
* (Ported from https://github.com/github/graphql-docs/blob/7e6a5ccbf13cc7d875fee65527b25bc49e886b41/lib/graphql_docs/update_internal_developer/change_log.rb#L230)
165+
* @param {Array<object>} changesToReport
166+
* @param {object} previews
167+
* @return {object}
168+
*/
144169
function segmentPreviewChanges(changesToReport, previews) {
145170
// Build a map of `{ path => previewTitle` }
146171
// for easier lookup of change to preview
@@ -238,6 +263,4 @@ const CHANGES_TO_IGNORE = [
238263
ChangeType.TypeDescriptionAdded,
239264
]
240265

241-
242-
243266
module.exports = { createChangelogEntry, cleanPreviewTitle, previewAnchor }

0 commit comments

Comments
 (0)