亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel Lighthouse GraphQL 更名為關系突變

Laravel Lighthouse GraphQL 更名為關系突變

PHP
慕村9548890 2022-08-05 10:05:37
我在更新與 graphQL 查詢重命名的關系時遇到問題。以下是相關的架構和Laravel模型:拉拉維爾模型<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\BelongsTo;use Illuminate\Database\Eloquent\Relations\BelongsToMany;class Lead extends Model{    /**     * The attributes that are mass assignable.     *     * @var array     */    // protected $fillable = [    //     'lead_type_id',    // ];    protected $guarded = [];    /**     * The attributes that should be hidden for arrays.     *     * @var array     */    protected $hidden = [        //    ];    /**     * The attributes that should be cast to native types.     *     * @var array     */    protected $casts = [        // 'created_at' => 'timestamp',        // 'updated_at' => 'timestamp'    ];    /**     * Get the LeadActions for the Lead.     */    public function leadActions()    {        return $this->hasMany(\App\Models\LeadAction::class);    }    /**     * Get the clients for the Lead.     */    public function clients(): BelongsToMany    {        return $this->belongsToMany(Client::class);    }    /**     * Get the LeadType for the Lead.     */    public function leadType(): BelongsTo    {        return $this->belongsTo(\App\Models\LeadType::class, 'lead_type_id');    }}?><?phpnamespace App\Models;use App\Models;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\HasMany;class LeadType extends Model{    /**     * The attributes that are mass assignable.     *     * @var array     */    protected $fillable = [        'name'    ];    /**     * The attributes that should be hidden for arrays.     *     * @var array     */    protected $hidden = [        //    ];我遵循了Laravel命名約定,并將列命名為lead_type_id在潛在客戶表上。如果我刪除將lead_type關系重命名為 leadType,我可以成功運行更新突變,但我無法弄清楚如何讓它使用列的正確名稱(lead_type_id),同時保持關系重命名。任何幫助都非常感謝。
查看完整描述

1 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

你試過指令嗎?我的意思是,你必須在你的中使用它,因為燈塔尋找名為的關系,并且由于沒有定義,它假設這是一個參數。@renamelead_typeUpdateLeadInputlead_typelead_type


在模型中重命名關系,例如:


class Lead extends Model

{

    public function lead_actions()

    {

        return $this->hasMany(\App\Models\LeadAction::class);

    }


    public function lead_type(): BelongsTo

    {

        return $this->belongsTo(\App\Models\LeadType::class, 'lead_type_id');

    }

}


使用指令(我沒有嘗試過,但我的意思是它的工作原理是這樣的):@rename


input UpdateLeadInput {

   id: ID!

   clients: UpdateClientsRelation

   lead_type: UpdateLeadTypeRelation @rename(attribute: "leadType")

}


查看完整回答
反對 回復 2022-08-05
  • 1 回答
  • 0 關注
  • 116 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號