Using the resolve() helper function in Nuwave\Lighthouse\Schema\Directives\RulesDirective and Nuwave\Lighthouse\Schema\Directives\RulesForArrayDirective brakes custom validation rules on Lumen.
Expected behavior/Solution
Using app() instead solves the problem, 'cos resolve() is just a helper function in Laravel (framework/src/Illuminate/Foundation/helpers.php):
if (! function_exists('resolve')) {
/**
* Resolve a service from the container.
*
* @param string $name
* @param array $parameters
* @return mixed
*/
function resolve($name, array $parameters = [])
{
return app($name, $parameters);
}
}
Describe the bug
Using the
resolve()
helper function inNuwave\Lighthouse\Schema\Directives\RulesDirective
andNuwave\Lighthouse\Schema\Directives\RulesForArrayDirective
brakes custom validation rules on Lumen.Expected behavior/Solution
Using
app()
instead solves the problem, 'cosresolve()
is just a helper function in Laravel (framework/src/Illuminate/Foundation/helpers.php
):https://github.com/albertcht/lumen-helpers is not a solution for this issue — it was last updated 2 years ago and doesn't have
resolve()
function.Steps to reproduce
app/Rules
Output/Logs
Click to expand
```json { "errors": [ { "debugMessage": "Call to undefined function Nuwave\\Lighthouse\\Schema\\Directives\\resolve()", "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 2, "column": 3 } ], "path": [ "updateClient" ], "trace": [ { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Schema\/Factories\/FieldFactory.php", "line": 313, "call": "Nuwave\\Lighthouse\\Schema\\Directives\\RulesDirective::rules()" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Schema\/Factories\/FieldFactory.php", "line": 273, "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::handleArgDirectives(instance of GraphQL\\Language\\AST\\InputValueDefinitionNode, array(1), instance of Illuminate\\Support\\Collection(1))" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Schema\/Factories\/FieldFactory.php", "line": 221, "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::handleArgWithAssociatedDirectives(GraphQLType: String, instance of GraphQL\\Language\\AST\\InputValueDefinitionNode, instance of Illuminate\\Support\\Collection(2), array(1))" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Schema\/Factories\/FieldFactory.php", "line": 153, "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::handleArgDirectivesRecursively(GraphQLType: String, instance of GraphQL\\Language\\AST\\InputValueDefinitionNode, array(1))" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 632, "call": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory::Nuwave\\Lighthouse\\Schema\\Factories\\{closure}(null, array(2), instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 555, "call": "GraphQL\\Executor\\ReferenceExecutor::resolveOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, instance of Closure, null, instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 478, "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Mutation, null, instance of ArrayObject(1), array(1))" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 921, "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'updateClient')" }, { "call": "GraphQL\\Executor\\ReferenceExecutor::GraphQL\\Executor\\{closure}(array(0), 'updateClient')" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 923, "function": "array_reduce(array(1), instance of Closure, array(0))" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 494, "call": "GraphQL\\Executor\\ReferenceExecutor::promiseReduce(array(1), instance of Closure, array(0))" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 256, "call": "GraphQL\\Executor\\ReferenceExecutor::executeFieldsSerially(GraphQLType: Mutation, null, array(0), instance of ArrayObject(1))" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/ReferenceExecutor.php", "line": 208, "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/Executor\/Executor.php", "line": 155, "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/GraphQL.php", "line": 158, "call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null)" }, { "file": "\/home\/mz\/test\/vendor\/webonyx\/graphql-php\/src\/GraphQL.php", "line": 90, "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, 'mutation {\n updateClient(\n id: 1\n name: \"NewName\"\n ) {\n id\n name\n updated_at\n }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/GraphQL.php", "line": 171, "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, 'mutation {\n updateClient(\n id: 1\n name: \"NewName\"\n ) {\n id\n name\n updated_at\n }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/GraphQL.php", "line": 110, "call": "Nuwave\\Lighthouse\\GraphQL::executeQuery('mutation {\n updateClient(\n id: 1\n name: \"NewName\"\n ) {\n id\n name\n updated_at\n }\n}', instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null)" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Support\/Http\/Controllers\/GraphQLController.php", "line": 70, "call": "Nuwave\\Lighthouse\\GraphQL::executeRequest(instance of Nuwave\\Lighthouse\\Execution\\LighthouseRequest)" }, { "call": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController::query(instance of Nuwave\\Lighthouse\\Execution\\LighthouseRequest)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/container\/BoundMethod.php", "line": 32, "function": "call_user_func_array(array(2), array(1))" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/container\/Util.php", "line": 36, "call": "Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/container\/BoundMethod.php", "line": 90, "call": "Illuminate\\Container\\Util::unwrapIfClosure(instance of Closure)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/container\/BoundMethod.php", "line": 34, "call": "Illuminate\\Container\\BoundMethod::callBoundMethod(instance of Laravel\\Lumen\\Application, array(2), instance of Closure)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/container\/Container.php", "line": 592, "call": "Illuminate\\Container\\BoundMethod::call(instance of Laravel\\Lumen\\Application, array(2), array(0), null)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 376, "call": "Illuminate\\Container\\Container::call(array(2), array(0))" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 319, "call": "Laravel\\Lumen\\Application::callControllerCallable(array(2), array(0))" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 278, "call": "Laravel\\Lumen\\Application::callControllerAction(array(3))" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 258, "call": "Laravel\\Lumen\\Application::callActionOnArrayBasedRoute(array(3))" }, { "call": "Laravel\\Lumen\\Application::Laravel\\Lumen\\Concerns\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Routing\/Pipeline.php", "line": 48, "function": "call_user_func(instance of Closure, instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Support\/Http\/Middleware\/AttemptAuthentication.php", "line": 42, "call": "Laravel\\Lumen\\Routing\\Pipeline::Laravel\\Lumen\\Routing\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/pipeline\/Pipeline.php", "line": 167, "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AttemptAuthentication::handle(instance of Laravel\\Lumen\\Http\\Request, instance of Closure, 'api')" }, { "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Routing\/Pipeline.php", "line": 30, "function": "call_user_func(instance of Closure, instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/nuwave\/lighthouse\/src\/Support\/Http\/Middleware\/AcceptJson.php", "line": 30, "call": "Laravel\\Lumen\\Routing\\Pipeline::Laravel\\Lumen\\Routing\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/pipeline\/Pipeline.php", "line": 167, "call": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AcceptJson::handle(instance of Laravel\\Lumen\\Http\\Request, instance of Closure)" }, { "call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Routing\/Pipeline.php", "line": 30, "function": "call_user_func(instance of Closure, instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/illuminate\/pipeline\/Pipeline.php", "line": 103, "call": "Laravel\\Lumen\\Routing\\Pipeline::Laravel\\Lumen\\Routing\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 413, "call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 259, "call": "Laravel\\Lumen\\Application::sendThroughPipeline(array(2), instance of Closure)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 165, "call": "Laravel\\Lumen\\Application::handleFoundRoute(array(3))" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 416, "call": "Laravel\\Lumen\\Application::Laravel\\Lumen\\Concerns\\{closure}(instance of Laravel\\Lumen\\Http\\Request)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 171, "call": "Laravel\\Lumen\\Application::sendThroughPipeline(array(0), instance of Closure)" }, { "file": "\/home\/mz\/test\/vendor\/laravel\/lumen-framework\/src\/Concerns\/RoutesRequests.php", "line": 108, "call": "Laravel\\Lumen\\Application::dispatch(null)" }, { "file": "\/home\/mz\/test\/public\/index.php", "line": 28, "call": "Laravel\\Lumen\\Application::run()" } ] } ], "data": { "updateClient": null } } ```