Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export interface RawResolversConfig extends RawConfig {
* inputValue: true
* object: true
* defaultValue: true
* resolvers: true;
* ```
*/
avoidOptionals?: boolean | AvoidOptionalsConfig;
Expand Down Expand Up @@ -370,6 +371,22 @@ export interface RawResolversConfig extends RawConfig {
* @ignore
*/
directiveResolverMappings?: Record<string, string>;
/**
* @description Allow you to set the visitor class that will be used to traverse the graphql AST to generate
* the types.
*
*
* @exampleMarkdown
*
* ## Custom Visitor
*
* ```yaml
* plugins
* config:
* customVisitor: ./my-custom-visitor#VisitorClass
* ```
* **/
customVisitor?: string;
}

export type ResolverTypes = { [gqlType: string]: string };
Expand Down Expand Up @@ -431,6 +448,7 @@ export class BaseResolversVisitor<
mappers: transformMappers(rawConfig.mappers || {}, rawConfig.mapperTypeSuffix),
scalars: buildScalarsFromConfig(_schema, rawConfig, defaultScalars),
internalResolversPrefix: getConfigValue(rawConfig.internalResolversPrefix, '__'),
customVisitor: getConfigValue(rawConfig.customVisitor, null), // If custom visitor is not set, we will use the default one
...additionalConfig,
} as TPluginConfig);

Expand Down
13 changes: 12 additions & 1 deletion packages/plugins/typescript/resolvers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
}

const transformedSchema = config.federation ? addFederationReferencesToSchema(schema) : schema;
const visitor = new TypeScriptResolversVisitor({ ...config, directiveResolverMappings }, transformedSchema);

let visitor;

if (config.customVisitor) {
// @TODO: figure out how to use custom-visitor#VisirClass syntax
// instead of using default
const CustomVistor = require(config.customVisitor).default;
visitor = new CustomVistor({ ...config, directiveResolverMappings }, transformedSchema);
} else {
visitor = new TypeScriptResolversVisitor({ ...config, directiveResolverMappings }, transformedSchema);
}

const namespacedImportPrefix = visitor.config.namespacedImportName ? `${visitor.config.namespacedImportName}.` : '';

const astNode = getCachedDocumentNodeFromSchema(transformedSchema);
Expand Down