feat(ts-resolvers): Add ability to configure a custom resolver#8339
feat(ts-resolvers): Add ability to configure a custom resolver#8339dac09 wants to merge 1 commit into
Conversation
|
| * inputValue: true | ||
| * object: true | ||
| * defaultValue: true | ||
| * resolvers: true; |
There was a problem hiding this comment.
This was missing in the documentation :)
| if (config.customVisitor) { | ||
| // @TODO: figure out how to use custom-visitor#VisirClass syntax | ||
| // instead of using default | ||
| const CustomVistor = require(config.customVisitor).default; |
There was a problem hiding this comment.
I need a little guidance on how I can load the supplied string, in the same way mappers or resolverFn loads external imports!
There was a problem hiding this comment.
For loading modules correctly on both ESM and CJS the following is recommended:
graphql-code-generator/packages/graphql-codegen-cli/src/codegen.ts
Lines 33 to 52 in 25c76c1
There was a problem hiding this comment.
I was looking for the function that loads strings like this:
./my-custom-visitor#VisitorClass
is there a separate function for this?
There was a problem hiding this comment.
@n1ru4l, what I'm trying is using parseMapper so that the syntax for configuring an import stays the same.
It'll look a little like this:
import { ExternalParsedMapper, parseMapper } from '@graphql-codegen/visitor-plugin-common';
const parsedVisitorString = parseMapper(config.customVisitor) as ExternalParsedMapper;This way you can specify the name of the class, rather than have to specifically use the default export.
It also looks like the makeDefaultLoader is in the codegen-cli package, should I duplicate it in this one? I'll need to spend a bit more time on this, but hopefully async imports are possible in a visitor!
|
I am fine with this change if proper tests are supplied. In a future major change, we might move completely away from the visitor pattern. No ETA for this yet, though. It will probably first happen for the typescript-client plugin. |
Draft PR (WIP) - one way to implement the feature described in #8338
Description
In Redwood, we need the ability to slightly modify how the TypeScriptResolversVisitor works, while keeping all of the other functionality within the typescript-resolvers plugin as is.
I've tried to describe what we're trying to achieve in this recording: https://s.tape.sh/xK6JyeYz?s=1.25
Related #8338
Type of change
How Has This Been Tested?
This is a draft PR for discussion, I will add tests as advised!
Test Environment:
Checklist: