-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency maintenance #76
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 2.0.0 - 2024-01-08 | ||
|
||
There are no interface changes in this release, but the minimum required Node.js version is now 18. | ||
|
||
### Changes | ||
|
||
- BREAKING: Require Node.js 18 or higher. | ||
- Fix issue where includeCrossReferences would incorrectly behave as if it was set to false in the presence of unions. | ||
- Upgrade dependencies: `commander`, `graphql` to latest | ||
- Remove dependency `del`, instead `rimraf` is now used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ const fs = require('fs'); | |
const path = require('path'); | ||
const program = require('commander'); | ||
const { Source, buildSchema } = require('graphql'); | ||
const del = require('del'); | ||
const { rimrafSync } = require('rimraf'); | ||
|
||
function main ({ | ||
function main({ | ||
schemaFilePath, | ||
destDirPath, | ||
depthLimit = 100, | ||
|
@@ -23,7 +23,7 @@ function main ({ | |
const source = new Source(typeDef); | ||
const gqlSchema = buildSchema(source, { assumeValidSDL: assume }); | ||
|
||
del.sync(destDirPath); | ||
rimrafSync(destDirPath); | ||
path.resolve(destDirPath).split(path.sep).reduce((before, cur) => { | ||
const pathTmp = path.join(before, cur + path.sep); | ||
if (!fs.existsSync(pathTmp)) { | ||
|
@@ -61,15 +61,15 @@ function main ({ | |
* Generate variables string | ||
* @param dict dictionary of arguments | ||
*/ | ||
const getArgsToVarsStr = dict => Object.entries(dict) | ||
const getArgsToVarsStr = (dict) => Object.entries(dict) | ||
.map(([varName, arg]) => `${arg.name}: $${varName}`) | ||
.join(', '); | ||
|
||
/** | ||
* Generate types string | ||
* @param dict dictionary of arguments | ||
*/ | ||
const getVarsToTypesStr = dict => Object.entries(dict) | ||
const getVarsToTypesStr = (dict) => Object.entries(dict) | ||
.map(([varName, arg]) => `$${varName}: ${arg.type}`) | ||
.join(', '); | ||
|
||
|
@@ -108,19 +108,25 @@ function main ({ | |
) { | ||
return ''; | ||
} | ||
if (!fromUnion) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the bug fix I mentioned. |
||
crossReferenceKeyList.push(crossReferenceKey); | ||
} | ||
crossReferenceKeyList.push(crossReferenceKey); | ||
const childKeys = Object.keys(curType.getFields()); | ||
childQuery = childKeys | ||
.filter((fieldName) => { | ||
/* Exclude deprecated fields */ | ||
const fieldSchema = gqlSchema.getType(curType).getFields()[fieldName]; | ||
return includeDeprecatedFields || !fieldSchema.deprecationReason; | ||
}) | ||
.map(cur => generateQuery(cur, curType, curName, argumentsDict, duplicateArgCounts, | ||
crossReferenceKeyList, curDepth + 1, fromUnion).queryStr) | ||
.filter(cur => Boolean(cur)) | ||
.map((cur) => generateQuery( | ||
cur, | ||
curType, | ||
curName, | ||
argumentsDict, | ||
duplicateArgCounts, | ||
crossReferenceKeyList, | ||
curDepth + 1, | ||
fromUnion, | ||
).queryStr) | ||
.filter((cur) => Boolean(cur)) | ||
.join('\n'); | ||
} | ||
|
||
|
@@ -143,15 +149,23 @@ function main ({ | |
const indent = `${' '.repeat(curDepth)}`; | ||
const fragIndent = `${' '.repeat(curDepth + 1)}`; | ||
queryStr += '{\n'; | ||
queryStr += `${fragIndent}__typename\n` | ||
queryStr += `${fragIndent}__typename\n`; | ||
|
||
for (let i = 0, len = types.length; i < len; i++) { | ||
const valueTypeName = types[i]; | ||
const valueType = gqlSchema.getType(valueTypeName); | ||
const unionChildQuery = Object.keys(valueType.getFields()) | ||
.map(cur => generateQuery(cur, valueType, curName, argumentsDict, duplicateArgCounts, | ||
crossReferenceKeyList, curDepth + 2, true).queryStr) | ||
.filter(cur => Boolean(cur)) | ||
.map((cur) => generateQuery( | ||
cur, | ||
valueType, | ||
curName, | ||
argumentsDict, | ||
duplicateArgCounts, | ||
crossReferenceKeyList, | ||
curDepth + 2, | ||
true, | ||
).queryStr) | ||
.filter((cur) => Boolean(cur)) | ||
.join('\n'); | ||
|
||
/* Exclude empty unions */ | ||
|
@@ -249,18 +263,22 @@ function main ({ | |
fs.writeFileSync(path.join(destDirPath, 'index.js'), indexJsExportAll); | ||
} | ||
|
||
module.exports = main | ||
module.exports = main; | ||
|
||
if (require.main === module) { | ||
program | ||
.name('gqlg') | ||
.option('--schemaFilePath [value]', 'path of your graphql schema file') | ||
.option('--destDirPath [value]', 'dir you want to store the generated queries') | ||
.option('--depthLimit [value]', 'query depth you want to limit (The default is 100)') | ||
.option('--assumeValid [value]', 'assume the SDL is valid (The default is false)') | ||
.option('--ext [value]', 'extension file to use', 'gql') | ||
.option('-C, --includeDeprecatedFields [value]', 'Flag to include deprecated fields (The default is to exclude)') | ||
.option('-R, --includeCrossReferences', 'Flag to include fields that have been added to parent queries already (The default is to exclude)') | ||
.showHelpAfterError() | ||
.parse(process.argv); | ||
|
||
return main({...program, fileExtension: program.ext }) | ||
const { ext, ...opts } = program.opts(); | ||
|
||
main({ ...opts, fileExtension: ext }); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All formatting changes were done by eslint upgrades and running lint --fix.