在 Lighthouse 5 中,报错:Failed to find class Modules\\ThemeStore\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator in namespaces [App\\GraphQL\\Validators] for directive @validator.
1、在 Lighthouse 5 中,报错:Failed to find class Modules\\ThemeStore\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator in namespaces [App\\GraphQL\\Validators] for directive @validator.。如图1
PS E:\wwwroot\object> php artisan lighthouse:ide-helper Wrote schema directive definitions to E:\wwwroot\object/schema-directives.graphql. Nuwave\Lighthouse\Exceptions\DefinitionException : Failed to find class Modules\ThemeStore\Validators\ThemeAsset\CreateThemeAssetInputValidator in namespaces [App\GraphQL\Validators] for directive @validator. at E:\wwwroot\object\vendor\nuwave\lighthouse\src\Schema\Directives\BaseDirective.php:200 196| ); 197| 198| if (! $className) { 199| $consideredNamespaces = implode(', ', $namespacesToTry); > 200| throw new DefinitionException( 201| "Failed to find class {$classCandidate} in namespaces [{$consideredNamespaces}] for directive @{$this->name()}." 202| ); 203| } 204| Exception trace: 1 Nuwave\Lighthouse\Schema\Directives\BaseDirective::namespaceClassName("Modules\ThemeStore\Validators\ThemeAsset\CreateThemeAssetInputValidator", Object(Closure)) E:\wwwroot\object\vendor\nuwave\lighthouse\src\Validation\ValidatorDirective.php:151 2 Nuwave\Lighthouse\Validation\ValidatorDirective::namespaceValidatorClass("Modules\ThemeStore\Validators\ThemeAsset\CreateThemeAssetInputValidator") E:\wwwroot\object\vendor\nuwave\lighthouse\src\Validation\ValidatorDirective.php:124 Please use the argument -v to see more details.
2、确认类 Modules\\ThemeStore\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator 已经迁移至 Modules\\ThemeStoreGraphQl\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator 。如图2
3、在指令 @validator 中的类文件路径调整为:Modules\\ThemeStoreGraphQl\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator 后,不再报错。
input ThemeAssetCreateInput @validator(class: "Modules\\ThemeStore\\Validators\\ThemeAsset\\CreateThemeAssetInputValidator") { "主题ID" themeId: String!, "内容" content: String!, "路径,相对于主题的路径,如 pages/index.blade.php" key: String!, }
近期评论