I am trying to get the 'Utilize the Viewer Pattern' of the Lighthouse Framework to work in my code (Laravel), but I cant access the data (Comments) created by the user.
I believe I implemented my comments.graphql correctly and I have the comments relationship in my model.
When I query with Insomnia I get NULL back even though the user is the same one creating the comments:
Any assistance would be great
comments.graphql:
enum CommentType {
Dossier @enum(value: "Blog")
}
type Comment {
id: ID!
body: String!
commentable_id: ID!
commentable_type: String!
}
type User {
name: String!
comments: [Comment!]!
}
type Query {
me: User! @auth
comments: [Comment!]! @all
}
type Mutation {
createComment(
body: String! @rules(apply: ["required", "min:2"])
commentable_type: CommentType!
): Comment! @create
updateComment(
id: ID!, @rules(apply: ["exists:comments,id", "required", "min:1"])
body: String! @rules(apply: ["required", "min:2"])
): Comment! @update
deleteComment(
id: ID! @rules(apply: ["required", "min:1"])
): Comment! @delete
}
Comment.php (Model):
<?php
namespace App\Models;
use App\Acme\Traits\Model\Creator;
use App\Acme\Traits\Model\Editor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Helper\BaseModel;
class Comment extends Model
{
protected $fillable = [
'body',
'commentable_id',
'commentable_type'
];
public function commentable()
{
return $this->morphTo();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
User.php contains the relationship:
public function comments()
{
return $this->morphMany(\App\Models\Comments::class, 'commentable')->withTimestamps();
}
Aucun commentaire:
Enregistrer un commentaire