首页 > 解决方案 > Laravel 返回 InvalidArgumentException 并显示消息“没有为 [graphql-playground] 定义提示路径”

问题描述

Lighthouse 教程说如果访问 /graphql-playground 会出现 GraphQL Playground 的视图,但是会抛出异常。我该如何解决?

当访问 /graphql-playground 时,抛出此异常:

InvalidArgumentException(code: 0): No hint path defined for [graphql-playground]

异常从以下位置抛出:

    protected function parseNamespaceSegments($name)
    {
        $segments = explode(static::HINT_PATH_DELIMITER, $name);

        if (count($segments) !== 2) {
            throw new InvalidArgumentException("View [{$name}] has an invalid name.");
        }

        if (! isset($this->hints[$segments[0]])) { // <- this line
            throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");
        }

        return $segments;
    }

我试过这个:

  1. 将 ServiceProvider 添加到 config.app.provider
        'providers' => [
        //
        \MLL\GraphQLPlayground\GraphQLPlaygroundServiceProvider::class,

    ],
  1. 发布包
php artisan vendor:publish --tag=graphql-playground-view
php artisan vendor:publish --tag=graphql-playground-config
php artisan vendor:publish --provider="MLL\GraphQLPlayground\GraphQLPlaygroundServiceProvider"

标签: phplaravelgraphqllaravel-lighthousegraphql-playground

解决方案


推荐阅读