-
-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inflector): better errors, overriding possible with makeAddInfle…
…ctorsPlugin (#315) * Improve clash comment * Give makeAddInflectorsPlugin a replace option
- Loading branch information
Showing
4 changed files
with
38 additions
and
12 deletions.
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 |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import { Plugin } from "graphile-build"; | ||
|
||
export default function makeAddInflectorsPlugin(additionalInflectors: { | ||
[str: string]: ((...args: Array<any>) => any); | ||
}): Plugin { | ||
export default function makeAddInflectorsPlugin( | ||
additionalInflectors: { | ||
[str: string]: ((...args: Array<any>) => any); | ||
}, | ||
replace = false | ||
): Plugin { | ||
return builder => { | ||
builder.hook("inflection", (inflection, build) => { | ||
return build.extend(inflection, additionalInflectors); | ||
if (replace) { | ||
// Overwrite directly so that we don't lose the 'extend' hints | ||
Object.assign(inflection, additionalInflectors); | ||
return inflection; | ||
} else { | ||
return build.extend( | ||
inflection, | ||
additionalInflectors, | ||
`Adding inflectors ('${Object.keys(additionalInflectors).join( | ||
"', '" | ||
)}') via makeAddInflectorsPlugin. You can pass \`true\` as the second argument to makeAddInflectorsPlugin to allow overwriting existing inflectors.` | ||
); | ||
} | ||
}); | ||
}; | ||
} |
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