Laravel's Lighthouse has directives to perform data-modifying CRUD operations directly on the database: @create
, @delete
, and @update
.
A simple CRUD's create can be implemented like this:
type Mutation {
createPost(title: String!): Post @create
}
This works, but it creates records without an owner. My question is: How to assign an user_id
to a newly created record?
I mean, without having to use a resolver.
I could add an user_id
parameter, like this:
type Mutation {
createPost(user_id: ID, title: String!): Post @create
}
But that would cause a huge security issue - anyone could add or change records of other users.