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