0

我正在尝试从我的 GraphQL 获取数据,但它返回此错误:

{
  "message": "Cannot declare class App\\GraphQL\\Mutations\\AcceptBooking, because the name is already in use",
  "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
  "file": "/Users/stevenvaneck/projects/hihiguide/app/Http/GraphQL/Mutations/AcceptBooking.php",
  "line": 14,
  "trace": []
}

AcceptBooking.php

<?php

namespace App\GraphQL\Mutations;

use Auth;
use App\Booking;
use App\Http\Controllers\Email\MailType;
use GraphQL\Type\Definition\ResolveInfo;
use App\Http\Controllers\Email\MailController;
use App\Jobs\Mail\Traveler\SendNewAvailableMail;
use App\Jobs\SMS\SendNewAvailableSMS;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

class AcceptBooking
{
    /**
     * Return a value for the field.
     *
     * @param null $rootValue Usually contains the result returned from the parent field. In this case, it is always `null`.
     * @param array $args The arguments that were passed into the field.
     * @param GraphQLContext|null $context Arbitrary data that is shared between all fields of a single query.
     * @param ResolveInfo $resolveInfo Information about the query itself, such as the execution state, the field name, path to the field from the root, and more.
     *
     * @return mixed
     */
    public function resolve($rootValue, array $args, GraphQLContext $context = null, ResolveInfo $resolveInfo)
    {

      //my code

    }
}

如果我将类的名称更改为随机名称,它再次表示我给它的新名称正在使用中。

在我的 schema.graphql

type Mutation {
    acceptBooking(data: AcceptInput): String @middleware(checks: ["auth:api"]) @field(resolver: "App\\Http\\GraphQL\\Mutations\\AcceptBooking@resolve")
    declineBooking(data: DeclineInput): String @middleware(checks: ["auth:api"]) @field(resolver: "App\\Http\\GraphQL\\Mutations\\DeclineBooking@resolve")
}

我在 Laravel 项目中使用 Lighthouse-php。

4

1 回答 1

3

我的命名空间路径不正确

namespace App\GraphQL\Mutations;

必须是

namespace App\GraphQL\Http\Mutations;
于 2020-03-10T11:39:02.150 回答