Hey community,
When i try to insert my merged map with the current_user.id
I get an error that my user id is not present.
My merged map looks like this:
%{
content: "Testing the post mutation",
published: false,
title: "Test post",
user_id: 3
}
The error looks like this
[error] #PID<0.427.0> running MediumGraphqlApiWeb.Endpoint (connection #PID<0.426.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api/graphiql
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Enumerable not implemented for
#Ecto.Changeset<action: :insert, changes:
%{content: "Testing the post mutation", title: "Test post"},
errors: [user_id: {"can't be blank", [validation: :required]}]
Also my resolver looks like this
defmodule MediumGraphqlApiWeb.Resolvers.PostResolver do
alias MediumGraphqlApi.Blog
def create_post(_, %{input: input}, %{context: %{current_user: current_user}}) do
post_input = Map.merge(input, %{user_id: current_user.id})
IO.inspect(post_input)
Blog.create_post(post_input)
end
end
All other mutations work login register and list users
Thanks in advance