And very odd error when passing arguments in graphql query

In a unit test, i launched a query which needs 3 parameters as follows:

@query """
    query ($container_type: String!, $container_id: UUID!, $limit: Int) {
      messages_for_container(container_type: $container_type, container_id: $container_id, limit: $limit) {
        messages {
          id
        }
      }
    }
"""
test "returns a limited number of messages", %{conn: conn, user: user} do
      ...
      conn =
        get(conn, "/graphql2",
          query: @query,
          variables: %{
            container_type: room.container_type,
            container_id: room.container_id,
            limit: 1
          }
        )

      assert %{"data" => data} = json_response(conn, 200)
      ...
    end

It failed with the following error:

%{"errors" => [%{"locations" => [...], "message" => "Argument \"limit\" has invalid value $limit."}] }

That mean limit parameter didn’t get the right value from what was passed.

What confused me most is that if i directly set limit to 1 and remove $limit totally, it passed:

@query """
    query ($container_type: String!, $container_id: UUID!) {
      messages_for_container(container_type: $container_type, container_id: $container_id, limit: 1) {
        messages {
          id
        }
      }
    }
"""
test "returns a limited number of messages", %{conn: conn, user: user} do
      ...
      conn =
        get(conn, "/graphql2",
          query: @query,
          variables: %{
            container_type: room.container_type,
            container_id: room.container_id,
          }
        )

      assert %{"data" => data} = json_response(conn, 200)
      ...
    end

So there is no problem with the schema. Anybody has some hints:

phoenix version: 1.7.7
absinthe version: 1.7.5

Hi @tomwang57 can you show the schema you have for that query field?

Sure, thanks for your rapid reply:

object :message_queries do
    @desc "Fetch the messages in a message container."
    field :messages_for_container, :messages_for_container_connection do
      arg :container_type, non_null(:string)
      arg :container_id, non_null(:uuid)
      arg :limit, :integer

      resolve(&WebInterface.GraphQL.Resolvers.Message.get_messages_for_container/3)
    end
end

# resolver:
def get_messages_for_container(_, args, %{context: %{viewer: viewer}}) do
    %{container_id: container_id, container_type: container_type} = args

    if authorized?(viewer, container_type) do
      %{user_id: user_id} = viewer

      limit = Map.get(args, :limit, 10)

      result =
        Chat.get_messages_for_container(user_id, container_type, container_id, limit: limit)

      case result do
        {:ok, messages} ->
          {:ok, %{messages: messages}}

        error ->
          error
      end
    else
      {:error, "unauthorized"}
    end
  end