dotansimha / dotansimha/graphql-code-generator
`pluginContext` is always an empty object
- 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.
I am building a custom plugin, and would like to have access to the raw options the user sets in the `generates` section. I thought the perfect spot for this would be `pluginContext`, passed down to the plugin handler as a property of the `info` argument. Nevertheless it is never filled with anything, I checked the code and unless there is something I didn't pay attention to, this is a useless field right now. I would like to know what is the original intention for this property and if there is the possibility to pass in the raw configuration for the `generates` section in which the plugin was used (i.e. unprocessed and containing the actual configuration that was used, either global or local).
For context, I would like to know the raw `schema` option, because I'm interested in the source URL for the schema, if the user provided an URL. If the schema is local or there are multiple schemas I'll instruct the plugin user to use the local `schema` option and set a URL there, instead of globally.
### Describe the solution you'd like
I would like to have the `pluginContext` property filled with the raw configuration for the generates section in which the specific plugin was used, instead of always being an empty object.
### Describe alternatives you've considered
For my specific case, I have considered asking the URL as a plugin configuration, but this could mean duplicate data for the user if they already have an URL to use as `schema`, it wouldn't be clear to them why they needed to copy it twice.
### Is your feature request related to a problem? Please describe.
My discovery comes from this line in execute-plugin.js:
```js
return profiler.run(() => Promise.resolve(plugin.plugin(outputSchema, documents, typeof options.config === 'object' ? { ...options.config } : options.config, {
outputFile: options.outputFilename,
allPlugins: options.allPlugins,
pluginContext, // ---> THIS ONE
})), `Plugin ${options.name} execution`);
}
```
I have searched for occurrences and how the pluginContext is set. It comes from the `CodegenContext`:
```js
constructor({ config, graphqlConfig, filepath, }) {
this._checkMode = false;
this._pluginContext = {}; // ---> HERE
this.checkModeStaleFiles = [];
this._config = config;
this._graphqlConfig = graphqlConfig;
this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
this.cwd = this._graphqlConfig ? this._graphqlConfig.dirpath : process.cwd();
this.profiler = createNoopProfiler();
}
```
...and it's never changed from this moment onwards.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.