laravel - Laravel Lighthouse 错误:响应不成功:收到状态码 500
问题描述
我正在将 laravel lighthouse 用于 graphql,在灯塔游乐场编写 graphql 查询时遇到此错误:
ServerError:响应不成功:收到状态码 500
bundle.esm.js:69 POST http://127.0.1.4/api 500(内部服务器错误)
当我打开灯塔游乐场页面时出现此错误,我什至没有机会编写查询。
这是我的灯塔配置文件,我只是将route
部分更改为api
还有这部分'enable' => env('LIGHTHOUSE_CACHE_ENABLE', false)
:
<?php
return [
'route' => [
'uri' => '/api',
'name' => 'api',
'middleware' => [
\Nuwave\Lighthouse\Support\Http\Middleware\AcceptJson::class,
\Nuwave\Lighthouse\Support\Http\Middleware\AttemptAuthentication::class,
],
],
'guard' => null,
'schema' => [
'register' => base_path('graphql/schema.graphql'),
],
'cache' => [
'enable' => env('LIGHTHOUSE_CACHE_ENABLE', false),
'key' => env('LIGHTHOUSE_CACHE_KEY', 'lighthouse-schema'),
'ttl' => env('LIGHTHOUSE_CACHE_TTL', null),
],
'namespaces' => [
'models' => 'App\\Models',
'queries' => 'App\\GraphQL\\Queries',
'mutations' => 'App\\GraphQL\\Mutations',
'subscriptions' => 'App\\GraphQL\\Subscriptions',
'interfaces' => 'App\\GraphQL\\Interfaces',
'unions' => 'App\\GraphQL\\Unions',
'scalars' => 'App\\GraphQL\\Scalars',
'directives' => ['App\\GraphQL\\Directives'],
],
'security' => [
'max_query_complexity' => \GraphQL\Validator\Rules\QueryComplexity::DISABLED,
'max_query_depth' => \GraphQL\Validator\Rules\QueryDepth::DISABLED,
'disable_introspection' => \GraphQL\Validator\Rules\DisableIntrospection::DISABLED,
],
'pagination' => [
'default_count' => 10,
'max_count' => null,
],
'pagination_amount_argument' => 'first',
'orderBy' => 'field',
'debug' => \GraphQL\Error\Debug::INCLUDE_DEBUG_MESSAGE | \GraphQL\Error\Debug::INCLUDE_TRACE,
'error_handlers' => [
\Nuwave\Lighthouse\Execution\ExtensionErrorHandler::class,
\Nuwave\Lighthouse\Execution\ReportingErrorHandler::class,
],
'global_id_field' => 'id',
'batched_queries' => true,
'transactional_mutations' => true,
'batchload_relations' => true,
'subscriptions' => [
'queue_broadcasts' => env('LIGHTHOUSE_QUEUE_BROADCASTS', true),
'broadcasts_queue_name' => env('LIGHTHOUSE_BROADCASTS_QUEUE_NAME', null),
'storage' => env('LIGHTHOUSE_SUBSCRIPTION_STORAGE', 'redis'),
'storage_ttl' => env('LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL', null),
'broadcaster' => env('LIGHTHOUSE_BROADCASTER', 'pusher'),
'broadcasters' => [
'log' => [
'driver' => 'log',
],
'pusher' => [
'driver' => 'pusher',
'routes' => \Nuwave\Lighthouse\Subscriptions\SubscriptionRouter::class.'@pusher',
'connection' => 'pusher',
],
],
],
'defer' => [
'max_nested_fields' => 0,
'max_execution_ms' => 0,
],
];
这是我的 CORS 配置文件,我只是将paths
部分更改为api
:
<?php
return [
'paths' => ['api/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
这是graphql的架构文件:
"A date string with format `Y-m-d`, e.g. `2011-05-23`."
scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")
"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")
"A datetime and timezone string in ISO 8601 format `Y-m-dTH:i:sO`, e.g. `2020-04-20T13:53:12+02:00`."
scalar DateTimeTz @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTimeTz")
type Query {
fields(input: ListInput @spread): [Field]
field(id: ID! @eq): Field @find(model: "App\\Field")
}
type Mutation {
createField(
name_en: String! @rules(apply: ["required"])
name_fa: String
description: String
img_url: String
): Field @create(model: "App\\Field")
updateField(
id: ID! @rules(apply: ["required", "int"])
name_en: String @rules(apply: ["required"])
name_fa: String
description: String
img_url: String
): Field @update(model: "App\\Field")
deleteField(
id: ID! @rules(apply: ["required", "int"])
): Field @delete(model: "App\\Field")
}
type Field {
id: ID!
name_en: String!
name_fa: String!
description: String!
img_url: String!
created_at: DateTime!
updated_at: DateTime!
subFields: [SubField] @hasMany
}
input ListInput {
page: Int @rules(apply: ["int"])
limit: Int @rules(apply: ["int"])
q: String @rules(apply: ["string", "max:191"])
}
我真的不知道问题是什么。希望你能帮我解决这个问题。
解决方案
替换 CORS 配置文件中的以下代码:
'paths' => ['api/*', 'graphql'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => false,
'max_age' => false,
'supports_credentials' => false,
推荐阅读
- java - Mirth 文件阅读器 - Java 堆空间错误
- java - XPath 断言将始终在 CamelTestSupport 类中传递
- java - 与LinkedList读写.txt文件相关的问题(文件内容读取与写入不同)
- java - 动态火花 sql 查询
- android - 在android studio中使用node js
- apache-spark - 如何使用火花滞后和领先于 group by 和 order by
- java - 如何在 Java 中使用 ScheduledThreadpoolExecutor 重新启动终止的线程?
- laravel - 如何使用 Laravel Passport 通过 API 测试身份验证?
- java - Raspan:从 Java/Tomcat 执行 Python 脚本,tomcat8 用户不接受
- swift - RLMException', reason: '试图在写事务之外修改对象