Describe the bug
Installed the latest version of Laravel , Lighthouse php , laravel passport. I want some of the routes be accessible only to the logged in users. I followed the documentation to use auth middleware. I am getting the error as:
errors": [
{
"debugMessage": "Route [login] not defined.",
"message": "Internal server error",
"category": "internal",
...
even though I have defined to use auth:api middleware.
Expected behavior
It should have sent not authenticated error in case of not logged in.
Schema
type Query {
users: [User!]!
@paginate(type: "paginator", model: "App\\User")
@middleware(checks: ["auth:api"])
user(id: ID @eq): User @find(model: "App\\User")
}
Output/Logs
Click to expand
{
"errors": [
{
"debugMessage": "Route [login] not defined.",
"message": "Internal server error",
"category": "internal",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"users"
],
"trace": [
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php",
"line": 822,
"call": "Illuminate\\Routing\\UrlGenerator::route('login', array(0), true)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/app/Http/Middleware/Authenticate.php",
"line": 18,
"function": "route('login')"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"line": 68,
"call": "App\\Http\\Middleware\\Authenticate::redirectTo(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"line": 41,
"call": "Illuminate\\Auth\\Middleware\\Authenticate::authenticate(instance of Illuminate\\Http\\Request, array(1))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Illuminate\\Auth\\Middleware\\Authenticate::handle(instance of Illuminate\\Http\\Request, instance of Closure, 'api')"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/nuwave/lighthouse/src/Support/Pipeline.php",
"line": 44,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"call": "Nuwave\\Lighthouse\\Support\\Pipeline::Nuwave\\Lighthouse\\Support\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/nuwave/lighthouse/src/Schema/Directives/Fields/MiddlewareDirective.php",
"line": 86,
"call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 781,
"call": "Nuwave\\Lighthouse\\Schema\\Directives\\Fields\\MiddlewareDirective::Nuwave\\Lighthouse\\Schema\\Directives\\Fields\\{closure}(null, array(1), instance of Nuwave\\Lighthouse\\Schema\\Context, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 739,
"call": "GraphQL\\Executor\\Executor::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/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 473,
"call": "GraphQL\\Executor\\Executor::resolveField(GraphQLType: Query, null, instance of ArrayObject(1), array(1))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 349,
"call": "GraphQL\\Executor\\Executor::executeFields(GraphQLType: Query, null, array(0), instance of ArrayObject(1))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 309,
"call": "GraphQL\\Executor\\Executor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromiseAdapter.php",
"line": 59,
"call": "GraphQL\\Executor\\Executor::GraphQL\\Executor\\{closure}(array(2), array(2))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 310,
"call": "GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter::create(instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 166,
"call": "GraphQL\\Executor\\Executor::doExecute()"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/GraphQL.php",
"line": 148,
"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/bijaya/Projects/Learn/laravel-graphql-vue/vendor/webonyx/graphql-php/src/GraphQL.php",
"line": 85,
"call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, '{\n users(count: 5) {\n paginatorInfo {\n perPage\n currentPage\n }\n data {\n name\n }\n }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/nuwave/lighthouse/src/GraphQL.php",
"line": 113,
"call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, '{\n users(count: 5) {\n paginatorInfo {\n perPage\n currentPage\n }\n data {\n name\n }\n }\n}', null, instance of Nuwave\\Lighthouse\\Schema\\Context, array(0), null, null, array(29))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/nuwave/lighthouse/src/Support/Http/Controllers/GraphQLController.php",
"line": 83,
"call": "Nuwave\\Lighthouse\\GraphQL::executeQuery('{\n users(count: 5) {\n paginatorInfo {\n perPage\n currentPage\n }\n data {\n name\n }\n }\n}', instance of Nuwave\\Lighthouse\\Schema\\Context, array(0))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/nuwave/lighthouse/src/Support/Http/Controllers/GraphQLController.php",
"line": 62,
"call": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController::execute(instance of Illuminate\\Http\\Request)"
},
{
"call": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController::query(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
"line": 54,
"function": "call_user_func_array(array(2), array(1))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
"line": 45,
"call": "Illuminate\\Routing\\Controller::callAction('query', array(1))"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 219,
"call": "Illuminate\\Routing\\ControllerDispatcher::dispatch(instance of Illuminate\\Routing\\Route, instance of Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController, 'query')"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 176,
"call": "Illuminate\\Routing\\Route::runController()"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 682,
"call": "Illuminate\\Routing\\Route::run()"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"call": "Illuminate\\Routing\\Router::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 684,
"call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 659,
"call": "Illuminate\\Routing\\Router::runRouteWithinStack(instance of Illuminate\\Routing\\Route, instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 625,
"call": "Illuminate\\Routing\\Router::runRoute(instance of Illuminate\\Http\\Request, instance of Illuminate\\Routing\\Route)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 614,
"call": "Illuminate\\Routing\\Router::dispatchToRoute(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 176,
"call": "Illuminate\\Routing\\Router::dispatch(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"call": "Illuminate\\Foundation\\Http\\Kernel::Illuminate\\Foundation\\Http\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/fideloper/proxy/src/TrustProxies.php",
"line": 57,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Fideloper\\Proxy\\TrustProxies::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 31,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 31,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line": 27,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line": 62,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 151,
"call": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode::handle(instance of Illuminate\\Http\\Request, instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"call": "Illuminate\\Pipeline\\Pipeline::Illuminate\\Pipeline\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"call": "Illuminate\\Routing\\Pipeline::Illuminate\\Routing\\{closure}(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 151,
"call": "Illuminate\\Pipeline\\Pipeline::then(instance of Closure)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 116,
"call": "Illuminate\\Foundation\\Http\\Kernel::sendRequestThroughRouter(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/Projects/Learn/laravel-graphql-vue/public/index.php",
"line": 55,
"call": "Illuminate\\Foundation\\Http\\Kernel::handle(instance of Illuminate\\Http\\Request)"
},
{
"file": "/home/bijaya/.config/composer/vendor/cpriego/valet-linux/server.php",
"line": 204,
"function": "require('/home/bijaya/Projects/Learn/laravel-graphql-vue/public/index.php')"
}
]
}
],
"data": {
"users": null
}
}
Environment
Lighthouse Version: ^2.6
Laravel Version: 5.7.21
PHP Version: 7.3.1
Additional context
Try upgrading to dev-master please.
Still getting the same issue.
I think the docs might need some work. If someone who has mastered authentication can enhance the docs, that would be very welcome.
I found my mistake. I need to send headers while sending the request from the playground. Passing http header
{
"accept": "application/json"
}
solved my issue.