LastDragon-ru / lara-asp

Awesome Set of Packages for Laravel
MIT License
11 stars 1 forks source link

`@searchBy` stop working on Octane and `LIGHTHOUSE_CACHE=false` #38

Closed webard closed 2 years ago

webard commented 2 years ago

Hi,

on Laravel Octane with Swoole, and when LIGHTHOUSE_CACHE is set to false, after second request there is a bug:


  "errors": [
    {
      "debugMessage": "LastDragon_ru\\LaraASP\\GraphQL\\Builder\\Directives\\HandlerDirective::handle(): Argument #3 ($conditions) must be of type Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet, array given, called in /var/www/html/vendor/lastdragon-ru/lara-asp-graphql/src/Builder/Directives/HandlerDirective.php on line 61",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "users"
      ],
      "trace": [
        {
          "file": "/var/www/html/vendor/lastdragon-ru/lara-asp-graphql/src/Builder/Directives/HandlerDirective.php",
          "line": 61,
          "call": "LastDragon_ru\\LaraASP\\GraphQL\\Builder\\Directives\\HandlerDirective::handle()"
        },
        {
          "file": "/var/www/html/vendor/lastdragon-ru/lara-asp-graphql/src/SearchBy/Directives/Directive.php",
          "line": 54,
          "call": "LastDragon_ru\\LaraASP\\GraphQL\\Builder\\Directives\\HandlerDirective::handleAnyBuilder()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Execution/Arguments/ArgumentSet.php",
          "line": 129,
          "call": "LastDragon_ru\\LaraASP\\GraphQL\\SearchBy\\Directives\\Directive::handleBuilder()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php",
          "line": 262,
          "call": "Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet::Nuwave\\Lighthouse\\Execution\\Arguments\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Execution/Arguments/ArgumentSet.php",
          "line": 130,
          "call": "Illuminate\\Support\\Collection::each()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Execution/Arguments/ArgumentSet.php",
          "line": 88,
          "call": "Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet::applyArgBuilderDirectives()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Pagination/PaginateDirective.php",
          "line": 129,
          "call": "Nuwave\\Lighthouse\\Execution\\Arguments\\ArgumentSet::enhanceBuilder()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Auth/CanDirective.php",
          "line": 151,
          "call": "Nuwave\\Lighthouse\\Pagination\\PaginateDirective::Nuwave\\Lighthouse\\Pagination\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Auth/GuardDirective.php",
          "line": 68,
          "call": "Nuwave\\Lighthouse\\Auth\\CanDirective::Nuwave\\Lighthouse\\Auth\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/ConvertEmptyStringsToNullDirective.php",
          "line": 48,
          "call": "Nuwave\\Lighthouse\\Auth\\GuardDirective::Nuwave\\Lighthouse\\Auth\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/DropArgsDirective.php",
          "line": 35,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\ConvertEmptyStringsToNullDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/RenameArgsDirective.php",
          "line": 35,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\DropArgsDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/SpreadDirective.php",
          "line": 34,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\RenameArgsDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/ArgTraversalDirective.php",
          "line": 27,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\SpreadDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Validation/ValidateDirective.php",
          "line": 50,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\ArgTraversalDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/ArgTraversalDirective.php",
          "line": 27,
          "call": "Nuwave\\Lighthouse\\Validation\\ValidateDirective::Nuwave\\Lighthouse\\Validation\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Directives/TrimDirective.php",
          "line": 54,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\ArgTraversalDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Schema/Factories/FieldFactory.php",
          "line": 97,
          "call": "Nuwave\\Lighthouse\\Schema\\Directives\\TrimDirective::Nuwave\\Lighthouse\\Schema\\Directives\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 623,
          "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::Nuwave\\Lighthouse\\Schema\\Factories\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 550,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1195,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 264,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeFields()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 215,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/Executor.php",
          "line": 156,
          "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 162,
          "call": "GraphQL\\Executor\\Executor::promiseToExecute()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 94,
          "call": "GraphQL\\GraphQL::promiseToExecute()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/GraphQL.php",
          "line": 268,
          "call": "GraphQL\\GraphQL::executeQuery()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/GraphQL.php",
          "line": 203,
          "call": "Nuwave\\Lighthouse\\GraphQL::executeParsedQuery()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/GraphQL.php",
          "line": 162,
          "call": "Nuwave\\Lighthouse\\GraphQL::parseAndExecuteQuery()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/GraphQL.php",
          "line": 121,
          "call": "Nuwave\\Lighthouse\\GraphQL::executeOperation()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Support/Utils.php",
          "line": 99,
          "call": "Nuwave\\Lighthouse\\GraphQL::Nuwave\\Lighthouse\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/GraphQL.php",
          "line": 120,
          "call": "Nuwave\\Lighthouse\\Support\\Utils::mapEach()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Support/Http/Controllers/GraphQLController.php",
          "line": 32,
          "call": "Nuwave\\Lighthouse\\GraphQL::executeOperationOrOperations()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
          "line": 48,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController::__invoke()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
          "line": 261,
          "call": "Illuminate\\Routing\\ControllerDispatcher::dispatch()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
          "line": 204,
          "call": "Illuminate\\Routing\\Route::runController()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
          "line": 725,
          "call": "Illuminate\\Routing\\Route::run()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 141,
          "call": "Illuminate\\Routing\\Router::Illuminate\\Routing\\{closure}()"
        },
        {
          "file": "/var/www/html/src/Core/GraphQL/Middleware/LogQueryComplexity.php",
          "line": 30,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Core\\GraphQL\\Middleware\\LogQueryComplexity::handle()"
        },
        {
          "file": "/var/www/html/vendor/inspector-apm/inspector-laravel/src/Middleware/WebRequestMonitoring.php",
          "line": 35,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Inspector\\Laravel\\Middleware\\WebRequestMonitoring::handle()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Support/Http/Middleware/EnsureXHR.php",
          "line": 55,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\EnsureXHR::handle()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Support/Http/Middleware/AttemptAuthentication.php",
          "line": 34,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AttemptAuthentication::handle()"
        },
        {
          "file": "/var/www/html/vendor/nuwave/lighthouse/src/Support/Http/Middleware/AcceptJson.php",
          "line": 27,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AcceptJson::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 116,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
          "line": 726,
          "call": "Illuminate\\Pipeline\\Pipeline::then()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
          "line": 703,
          "call": "Illuminate\\Routing\\Router::runRouteWithinStack()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
          "line": 667,
          "call": "Illuminate\\Routing\\Router::runRoute()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
          "line": 656,
          "call": "Illuminate\\Routing\\Router::dispatchToRoute()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
          "line": 167,
          "call": "Illuminate\\Routing\\Router::dispatch()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 141,
          "call": "Illuminate\\Foundation\\Http\\Kernel::Illuminate\\Foundation\\Http\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php",
          "line": 45,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Sentry\\Laravel\\Http\\SetRequestIpMiddleware::handle()"
        },
        {
          "file": "/var/www/html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php",
          "line": 42,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Sentry\\Laravel\\Http\\SetRequestMiddleware::handle()"
        },
        {
          "file": "/var/www/html/src/Core/Http/Middleware/ServerTimingMiddleware.php",
          "line": 44,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Core\\Http\\Middleware\\ServerTimingMiddleware::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
          "line": 21,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php",
          "line": 31,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
          "line": 21,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php",
          "line": 40,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
          "line": 27,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
          "line": 86,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php",
          "line": 62,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Http\\Middleware\\HandleCors::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php",
          "line": 39,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 180,
          "call": "Illuminate\\Http\\Middleware\\TrustProxies::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
          "line": 116,
          "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
          "line": 142,
          "call": "Illuminate\\Pipeline\\Pipeline::then()"
        },
        {
          "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
          "line": 111,
          "call": "Illuminate\\Foundation\\Http\\Kernel::sendRequestThroughRouter()"
        },
        {
          "file": "/var/www/html/vendor/laravel/octane/src/ApplicationGateway.php",
          "line": 36,
          "call": "Illuminate\\Foundation\\Http\\Kernel::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/octane/src/Worker.php",
          "line": 92,
          "call": "Laravel\\Octane\\ApplicationGateway::handle()"
        },
        {
          "file": "/var/www/html/vendor/laravel/octane/bin/swoole-server",
          "line": 118,
          "call": "Laravel\\Octane\\Worker::handle()"
        },
        {
          "function": "{closure}()"
        },
        {
          "file": "/var/www/html/vendor/laravel/octane/bin/swoole-server",
          "line": 164,
          "call": "Swoole\\Server::start()"
        }
      ]
    }
  ]
}

First request is always successful. When cache is enable, everything is OK. My schema is super simple:

type Query {
users(
    filter: UserFilter @searchBy
  ): [User]
    @paginate(type: PAGINATOR)
    @softDeletes
    @guard
}

input UserFilter {
  id: ID
  firstname: String
  email: String
}

type User @model(class: "Modules\\User\\Entities\\User") {
  id: ID!
  firstname: String
  email: String
}

and the query is:

query {
  users(
    first: 51
    page: 1
    filter: {
      email: {
        like: "%gmail%"
      }
    }
  ) {
    paginatorInfo {
      count
      lastPage
      total
      hasMorePages
    }
    data {
      firstname
      email
    }
  }
}

All versions of framework, lighthouse and lara-asp are latest: 9.28, 5.58.2, 1.0.4.

LastDragon-ru commented 2 years ago

Thanks for the report. Unfortunately I've never tried Octan so it will take some time to install and debug.

webard commented 2 years ago

I think one of reason can be something from this documentation: https://laravel.com/docs/9.x/octane#dependency-injection-and-octane

I try do something by myself and open PR, but your help will be great value. Your package is awesome, and with Octane, which is supported by Lighthouse too, is 10x faster.

LastDragon-ru commented 2 years ago

I cannot reproduce it with Swoole v4.8.11, Laravel v9.29.0, Octane v1.3.1, Lighthouse v5.60.0 and Lara v1.0.4.

Could you please check value of LIGHTHOUSE_QUERY_CACHE_ENABLE and if it is enabled try to disable it? Or maybe you can create a repo with minimal reproduction?

webard commented 2 years ago

Sure, I try to prepare repository.

webard commented 2 years ago

Problem solved. I had code like this:

class GraphQLServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $typeRegistry = app(TypeRegistry::class);
        $dispatcher = app(\Illuminate\Contracts\Events\Dispatcher::class);
        $dispatcher->listen(
            \Nuwave\Lighthouse\Events\BuildSchemaString::class,
            function () use ($typeRegistry): string {

...

And calling $typeRegistry or $dispatcher like above causes problem when Swoole was booted (on second request).

I changed this to:

 Event::listen(
            \Nuwave\Lighthouse\Events\BuildSchemaString::class,
            function (): string {
                $typeRegistry = app(TypeRegistry::class);

...

and problem was gone.