【问题标题】:Laravel Lighthouse Error: Response not successful: Received status code 500Laravel Lighthouse 错误:响应不成功:收到状态码 500
【发布时间】:2020-06-03 04:57:13
【问题描述】:

我将 laravel lighthouse 用于 graphql,在 lighthouse playground 中编写 graphql 查询时遇到此错误:

ServerError:响应不成功:收到状态码 500

bundle.esm.js:69 POST http://127.0.1.4/api500(内部服务器错误)

我在打开灯塔游乐场页面时收到此错误,我什至没有机会编写查询。

这是我的灯塔配置文件,我只是将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"])
}

我真的不知道问题是什么。希望你能帮我解决这个问题。

【问题讨论】:

    标签: laravel graphql lighthouse


    【解决方案1】:

    在 CORS 配置文件中替换以下代码:

    'paths' => ['api/*', 'graphql'],
    'allowed_methods' => ['*'],
    'allowed_origins' => ['*'],
    'allowed_origins_patterns' => [],
    'allowed_headers' => ['*'],
    'exposed_headers' => false,
    'max_age' => false,
    'supports_credentials' => false,
    

    【讨论】:

      猜你喜欢
      • 2021-04-02
      • 2020-12-27
      • 2019-02-16
      • 2019-04-27
      • 2020-07-09
      • 2018-12-28
      • 2022-12-20
      • 2019-07-28
      • 2021-09-05
      相关资源
      最近更新 更多