My tests were passing until I wrote the input_object block. In my ecto schema, the field title is non-null. Since I wanted the updation to take place with either title or slug(there are some cases when I don’t want to update the title but just the slug), I wrote the input_object. But this landed me in a new error which I am not able to fix. Invalid argument value.
Gql muation for update
@desc "Update a Post"
field :update_post, :post do
arg(:id, non_null(:string))
arg(:title, :title_input)
arg(:slug, :slug_input)
resolve(&Resolvers.Post.update_post/3)
end
input_object :title_input do
field :title, :string
end
input_object :slug_input do
field :slug, :string
end
Resolver function
def update_post(_root, args, %{context: %{current_user: current_user}}) do
post_id = args.id
post =
Blog.get_post!(post_id)
case Blog.update_post(
post,
args,
current_user.current_tenant
) do
{:ok, post} ->
{:ok, post}
{:error, changeset} ->
{:error,
message: "Could not update post",
details: ChangesetErrors.error_details(changeset)}
end
Mutation test
mutation = """
mutation {
updatePost(id: "#{context.post.id}", title: "New title") {
id
title
slug
}
}
"""
expected_response = %{
"updatePost" => %{
"id" => context.post.id,
"title" => "New title"
}
}
Error message
"message" => "Argument \"title\" has invalid value \"New title\"."
Any help is appreciated.