Laravel LightHouse GraphQL DateTime突变输入始终为空

问题描述

我正在学习Laravel和LightHouse,并试图创建一个采用DateTime并将其放入数据库的变异。每次我通过DateTime进行突变时,输入都不会显示,而是被标记为null,这会在数据库中引发错误,因为表不允许DateTime为null。我所有其他值都工作得很好,所以我很困惑。 GraphQL Playground引发的错误为fetchProjectsError

在GraphQL游乐场中尝试过的这种突变:

SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column \"date_of_birth\" violates not-null constraint\nDETAIL:  Failing row contains (17,Blaze,[email protected],null,ABadPassword,2020-08-26 19:54:38,null). (SQL: insert into \"users\" (\"username\",\"password\",\"email\",\"updated_at\",\"created_at\") values (Blaze,2020-08-26 19:54:38) returning \"id\")"

这是我的模式:

mutation {
 createUser(
  username: "Blaze"
  email: "[email protected]"
  password: "ABadPassword"
  date_of_birth: "1998-01-16 00:00:00"
){
  id
 }
}

这是我在应用程序中的User.php文件中的用户:

"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")

type Mutation {
createUser(
    username: String @rules(apply: ["required","unique:users,username"]),password: String @rules(apply: ["required"]),email: String @rules(apply: ["required",email"]),date_of_birth: DateTime @rules(apply: ["required"])
): User! @create
}

type User {
  id: ID!
  username: String!
  email: String!
  email_verified_at: DateTime
  password: String!
  created_at: DateTime!
  updated_at: DateTime!
  date_of_birth: DateTime!
}

这是我在数据库中通过迁移创建的表:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'username','email','password','date_of_birth' => 'datetime'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password','remember_token',];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',];
}

希望这为错误提供了足够的背景信息,并感谢您的提前帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)