dotansimha / dotansimha/graphql-code-generator
Add support for custom loader params
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Is your feature request related to a problem? Please describe.**
My primary goal is to hide certain enum values from the generated types. For the schema like:
```graphql
enum MyEnum {
FIRST
SECOND
THIRD @ignore
}
```
I would like to generate Typescript enum with just `FIRST` and `SECOND`. I figured out that the best way to achieve that is a [custom loader](https://www.graphql-code-generator.com/docs/getting-started/schema-field#custom-schema-loader).
I need a way to tell the custom loader that my app is ready to support `THIRD` value and `@ignore` directive should no longer be respected for that particular value.
**Describe the solution you'd like**
```js
generates: {
schema: {
'my-schema.graphql': {
loader: './schemaLoader.js',
options: {
supportedEnums: ['MyEnum.THIRD']
}
}
}
}
```
and then in the loader
```js
module.exports = function (schemaString, config) {
console.log({ supportedEnums: config.loaderOptions.supportedEnums })
```
**Describe alternatives you've considered**
#### Sharing global config with the loader
Expose a global config to the custom loader
```js
generates: {
schema: {
'my-schema.graphql': {
loader: './schemaLoader.js'
}
},
config: {
supportedEnums: ['MyEnum.THIRD']
}
}
```
and then in the loader
```js
module.exports = function (schemaString, config) {
console.log({ supportedEnums: config.SOME_NAMESPACE.supportedEnums })
```
#### Another config file
A custom schema loader can load it's config from the file system like
```js
module.exports = function (schemaString, config) {
const configFilePath = `${schemaString}.json`
// Read supportedEnums from the config file
```
This way no changes are required to the generator, although it creates one more config file.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.