I am working with Echo, the web framework, MariaDB, and Prisma 2.
Exercising CRUD simple posts, I encountered the problem when i update one post.
I have let route "post/:id", which makes the post be updated. And uri parameter is id, such as 1, 2, 3
In Echo framework, uri parameters can be accessed with c.Param("id").
I triggered POST request with JSON object which includes title, and description as desc.
But the terminal said the error pql error: Error in query graph construction: QueryParserError(QueryParserError { path: QueryPath { segments: ["Mutation", "updateOnePost"] }, error_kind: FieldNotFoundError }).
I have predicted that if i launch post request to /posts/3, then title and content in post with id 3 should be changed, but not.
I am going to attach Prisma schema code, echo request handler code, and JSON request body.
I am using MariaDB, not PostgreSQL.
model post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime
title String
published Boolean
desc String?
type Post struct {
Title string `json:"title"`
Desc string `json:"desc"`
}
var client *db.PrismaClient = db.NewClient()
var ctx context.Context
func init() {
ctx = context.Background()
if err := client.Connect(); err != nil {
log.Panicln(err)
}
}
// UpdatePost Modifies a Post Being Already Created
func UpdatePost(c echo.Context) error {
p := new(Post)
if err := c.Bind(p); err != nil {
log.Println(err.Error())
return c.JSON(http.StatusBadRequest, echo.Map{
"status": "fail",
"msg": "Server Error",
})
}
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
log.Println(err.Error())
return c.JSON(http.StatusBadRequest, echo.Map{
"status": "fail",
"msg": "Server Error",
})
}
post, err := client.Post.FindOne(
db.Post.ID.Equals(id),
).Update(
db.Post.UpdatedAt.Set(time.Now()),
db.Post.Title.Set(p.Title),
db.Post.Published.Set(true),
db.Post.Desc.Set(p.Desc),
).Exec(ctx)
if err != nil {
log.Println(err.Error())
return c.JSON(http.StatusBadRequest, echo.Map{
"status": "fail",
"msg": "Server Error",
})
}
str, err := json.MarshalIndent(post, "", " ")
if err != nil {
log.Println(err.Error())
return c.JSON(http.StatusBadRequest, echo.Map{
"status": "fail",
"msg": "Server Error",
})
}
return c.JSON(http.StatusOK, echo.Map{
"status": "OK",
"content-length": len(str),
"msg": "The Post was modified as You Want",
})
}
{
"title" : "Example Title Edited",
"desc": "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
}
the properties id, and createdAt is not required when creating.
I have installed prisma-client-go latest version many times, and Echo version is v4.
What is the problem?