-
From: #8296 (comment) I want to use the new
The first feature I need is to replace user-defined documents before executing plugins. It is probably what your team calls "optimize" (optimizeOperation). Currently, the only plugin that can optimize documents is the relay-operation-optimizer. GraphQL Code Generator internally has a special implementation for relay-operation-optimizer. One of the designs we could agree on might be to make the "optimize" a public API. 🤔 const config: CodegenConfig = {
schema: 'http://localhost:4000/graphql',
documents: ['src/App.tsx'],
generates: {
'./src/gql/': {
preset: 'client',
// ↓ Add this line ↓
optimizers: ['@graphql-codegen/relay-operation-optimizer'], // or ['my-documents-optimizer', 'other-optimizer']
plugins: ['my-plugin.ts'],
},
},
}; The second needed feature is an object that can pass data from the optimizer to the plugin. Because my plugin that generates some code needs unoptimized documents. For example, suppose I wrote the following optimizer: module.exports = {
optimizer(schema, documents, config) {
const newDocuments = myChangeDocumentsFunction(documents);
// ↓ Returns a context object
return { documents: newDocuments, context: { myPlugin: { originalDocuments: documents } } };
},
}; I want to refer to the context passed from the plugin. module.exports = {
plugin(schema, documents, config, context) {
return generateMyCode(schema, documents, context.myPlugin.originalDocuments);
},
}; That is all! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@charlypoly What do you think? Or can you tell me who I should discuss it with? |
Beta Was this translation helpful? Give feedback.
@charlypoly What do you think? Or can you tell me who I should discuss it with?