@graphql-codegen/visitor-plugin-common 6.0.0-alpha-20250311213828-b0b7e86bc292eaf1e1b50e494e0e1f7af2fef9d2 → 6.0.0-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -642,18 +642,12 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
642
642
|
const declarationKind = 'type';
|
|
643
643
|
return (parentName, avoidResolverOptionals) => {
|
|
644
644
|
const original = parent[key];
|
|
645
|
-
const baseType = (0, utils_js_1.getBaseTypeNode)(original.type);
|
|
646
|
-
const realType = baseType.name.value;
|
|
647
645
|
const parentType = this.schema.getType(parentName);
|
|
648
646
|
const meta = {};
|
|
649
647
|
if (this._federation.skipField({ fieldNode: original, parentType })) {
|
|
650
648
|
return { value: null, meta };
|
|
651
649
|
}
|
|
652
650
|
const contextType = this.getContextType(parentName, node);
|
|
653
|
-
const typeToUse = this.getTypeToUse(realType);
|
|
654
|
-
const mappedType = this._variablesTransformer.wrapAstTypeWithModifiers(typeToUse, original.type);
|
|
655
|
-
const subscriptionType = this._schema.getSubscriptionType();
|
|
656
|
-
const isSubscriptionType = subscriptionType && subscriptionType.name === parentName;
|
|
657
651
|
let argsType = hasArguments
|
|
658
652
|
? this.convertName(parentName +
|
|
659
653
|
(this.config.addUnderscoreToArgsType ? '_' : '') +
|
|
@@ -681,12 +675,35 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
681
675
|
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
682
676
|
federationTypeSignature: 'FederationType',
|
|
683
677
|
});
|
|
684
|
-
const mappedTypeKey =
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
.
|
|
688
|
-
|
|
689
|
-
|
|
678
|
+
const { mappedTypeKey, resolverType } = (() => {
|
|
679
|
+
const baseType = (0, utils_js_1.getBaseTypeNode)(original.type);
|
|
680
|
+
const realType = baseType.name.value;
|
|
681
|
+
const typeToUse = this.getTypeToUse(realType);
|
|
682
|
+
/**
|
|
683
|
+
* Turns GraphQL type to TypeScript types (`mappedType`) e.g.
|
|
684
|
+
* - String! -> ResolversTypes['String']>
|
|
685
|
+
* - String -> Maybe<ResolversTypes['String']>
|
|
686
|
+
* - [String] -> Maybe<Array<Maybe<ResolversTypes['String']>>>
|
|
687
|
+
* - [String!]! -> Array<ResolversTypes['String']>
|
|
688
|
+
*/
|
|
689
|
+
const mappedType = this._variablesTransformer.wrapAstTypeWithModifiers(typeToUse, original.type);
|
|
690
|
+
const subscriptionType = this._schema.getSubscriptionType();
|
|
691
|
+
const isSubscriptionType = subscriptionType && subscriptionType.name === parentName;
|
|
692
|
+
if (isSubscriptionType) {
|
|
693
|
+
return {
|
|
694
|
+
mappedTypeKey: `${mappedType}, "${node.name}"`,
|
|
695
|
+
resolverType: 'SubscriptionResolver',
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
const directiveMappings = node.directives
|
|
699
|
+
?.map(directive => this._directiveResolverMappings[directive.name])
|
|
700
|
+
.filter(Boolean)
|
|
701
|
+
.reverse() ?? [];
|
|
702
|
+
return {
|
|
703
|
+
mappedTypeKey: mappedType,
|
|
704
|
+
resolverType: directiveMappings[0] ?? 'Resolver',
|
|
705
|
+
};
|
|
706
|
+
})();
|
|
690
707
|
const signature = {
|
|
691
708
|
name: node.name,
|
|
692
709
|
modifier: avoidResolverOptionals ? '' : '?',
|
|
@@ -638,18 +638,12 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
638
638
|
const declarationKind = 'type';
|
|
639
639
|
return (parentName, avoidResolverOptionals) => {
|
|
640
640
|
const original = parent[key];
|
|
641
|
-
const baseType = getBaseTypeNode(original.type);
|
|
642
|
-
const realType = baseType.name.value;
|
|
643
641
|
const parentType = this.schema.getType(parentName);
|
|
644
642
|
const meta = {};
|
|
645
643
|
if (this._federation.skipField({ fieldNode: original, parentType })) {
|
|
646
644
|
return { value: null, meta };
|
|
647
645
|
}
|
|
648
646
|
const contextType = this.getContextType(parentName, node);
|
|
649
|
-
const typeToUse = this.getTypeToUse(realType);
|
|
650
|
-
const mappedType = this._variablesTransformer.wrapAstTypeWithModifiers(typeToUse, original.type);
|
|
651
|
-
const subscriptionType = this._schema.getSubscriptionType();
|
|
652
|
-
const isSubscriptionType = subscriptionType && subscriptionType.name === parentName;
|
|
653
647
|
let argsType = hasArguments
|
|
654
648
|
? this.convertName(parentName +
|
|
655
649
|
(this.config.addUnderscoreToArgsType ? '_' : '') +
|
|
@@ -677,12 +671,35 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
677
671
|
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
678
672
|
federationTypeSignature: 'FederationType',
|
|
679
673
|
});
|
|
680
|
-
const mappedTypeKey =
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
.
|
|
684
|
-
|
|
685
|
-
|
|
674
|
+
const { mappedTypeKey, resolverType } = (() => {
|
|
675
|
+
const baseType = getBaseTypeNode(original.type);
|
|
676
|
+
const realType = baseType.name.value;
|
|
677
|
+
const typeToUse = this.getTypeToUse(realType);
|
|
678
|
+
/**
|
|
679
|
+
* Turns GraphQL type to TypeScript types (`mappedType`) e.g.
|
|
680
|
+
* - String! -> ResolversTypes['String']>
|
|
681
|
+
* - String -> Maybe<ResolversTypes['String']>
|
|
682
|
+
* - [String] -> Maybe<Array<Maybe<ResolversTypes['String']>>>
|
|
683
|
+
* - [String!]! -> Array<ResolversTypes['String']>
|
|
684
|
+
*/
|
|
685
|
+
const mappedType = this._variablesTransformer.wrapAstTypeWithModifiers(typeToUse, original.type);
|
|
686
|
+
const subscriptionType = this._schema.getSubscriptionType();
|
|
687
|
+
const isSubscriptionType = subscriptionType && subscriptionType.name === parentName;
|
|
688
|
+
if (isSubscriptionType) {
|
|
689
|
+
return {
|
|
690
|
+
mappedTypeKey: `${mappedType}, "${node.name}"`,
|
|
691
|
+
resolverType: 'SubscriptionResolver',
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
const directiveMappings = node.directives
|
|
695
|
+
?.map(directive => this._directiveResolverMappings[directive.name])
|
|
696
|
+
.filter(Boolean)
|
|
697
|
+
.reverse() ?? [];
|
|
698
|
+
return {
|
|
699
|
+
mappedTypeKey: mappedType,
|
|
700
|
+
resolverType: directiveMappings[0] ?? 'Resolver',
|
|
701
|
+
};
|
|
702
|
+
})();
|
|
686
703
|
const signature = {
|
|
687
704
|
name: node.name,
|
|
688
705
|
modifier: avoidResolverOptionals ? '' : '?',
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "6.0.0-alpha-
|
|
3
|
+
"version": "6.0.0-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@graphql-tools/optimize": "^2.0.0",
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250321102504-0b0c9bfb30ea7c446d896d8710d715701d90846a",
|
|
10
10
|
"@graphql-tools/relay-operation-optimizer": "^7.0.0",
|
|
11
11
|
"@graphql-tools/utils": "^10.0.0",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
@@ -510,6 +510,40 @@ export interface RawResolversConfig extends RawConfig {
|
|
|
510
510
|
* ```
|
|
511
511
|
*/
|
|
512
512
|
enumSuffix?: boolean;
|
|
513
|
+
/**
|
|
514
|
+
* @description Configures behavior for custom directives from various GraphQL libraries.
|
|
515
|
+
* @exampleMarkdown
|
|
516
|
+
* ## `@semanticNonNull`
|
|
517
|
+
* First, install `graphql-sock` peer dependency:
|
|
518
|
+
*
|
|
519
|
+
* ```sh npm2yarn
|
|
520
|
+
* npm install -D graphql-sock
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* Now, you can enable support for `@semanticNonNull` directive:
|
|
524
|
+
*
|
|
525
|
+
* ```ts filename="codegen.ts"
|
|
526
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
527
|
+
*
|
|
528
|
+
* const config: CodegenConfig = {
|
|
529
|
+
* // ...
|
|
530
|
+
* generates: {
|
|
531
|
+
* 'path/to/file.ts': {
|
|
532
|
+
* plugins: ['typescript-resolvers'],
|
|
533
|
+
* config: {
|
|
534
|
+
* customDirectives: {
|
|
535
|
+
* semanticNonNull: true
|
|
536
|
+
* }
|
|
537
|
+
* },
|
|
538
|
+
* },
|
|
539
|
+
* },
|
|
540
|
+
* };
|
|
541
|
+
* export default config;
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
customDirectives?: {
|
|
545
|
+
semanticNonNull?: boolean;
|
|
546
|
+
};
|
|
513
547
|
/**
|
|
514
548
|
* @default false
|
|
515
549
|
* @description Sets the `__resolveType` field as optional field.
|
|
@@ -510,6 +510,40 @@ export interface RawResolversConfig extends RawConfig {
|
|
|
510
510
|
* ```
|
|
511
511
|
*/
|
|
512
512
|
enumSuffix?: boolean;
|
|
513
|
+
/**
|
|
514
|
+
* @description Configures behavior for custom directives from various GraphQL libraries.
|
|
515
|
+
* @exampleMarkdown
|
|
516
|
+
* ## `@semanticNonNull`
|
|
517
|
+
* First, install `graphql-sock` peer dependency:
|
|
518
|
+
*
|
|
519
|
+
* ```sh npm2yarn
|
|
520
|
+
* npm install -D graphql-sock
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* Now, you can enable support for `@semanticNonNull` directive:
|
|
524
|
+
*
|
|
525
|
+
* ```ts filename="codegen.ts"
|
|
526
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
527
|
+
*
|
|
528
|
+
* const config: CodegenConfig = {
|
|
529
|
+
* // ...
|
|
530
|
+
* generates: {
|
|
531
|
+
* 'path/to/file.ts': {
|
|
532
|
+
* plugins: ['typescript-resolvers'],
|
|
533
|
+
* config: {
|
|
534
|
+
* customDirectives: {
|
|
535
|
+
* semanticNonNull: true
|
|
536
|
+
* }
|
|
537
|
+
* },
|
|
538
|
+
* },
|
|
539
|
+
* },
|
|
540
|
+
* };
|
|
541
|
+
* export default config;
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
customDirectives?: {
|
|
545
|
+
semanticNonNull?: boolean;
|
|
546
|
+
};
|
|
513
547
|
/**
|
|
514
548
|
* @default false
|
|
515
549
|
* @description Sets the `__resolveType` field as optional field.
|