mobilizon/test/support/abinthe_helpers.ex

39 lines
763 B
Elixir
Raw Normal View History

2020-01-26 20:34:25 +01:00
defmodule Mobilizon.GraphQL.AbsintheHelpers do
@moduledoc """
Absinthe helpers for tests
"""
2020-01-26 20:34:25 +01:00
use Phoenix.ConnTest
2020-01-26 21:36:50 +01:00
@endpoint Mobilizon.Web.Endpoint
2020-01-26 20:34:25 +01:00
def query_skeleton(query, query_name) do
%{
"operationName" => "#{query_name}",
"query" => "query #{query_name} #{query}",
"variables" => "{}"
}
end
def mutation_skeleton(query) do
%{
"operationName" => "",
"query" => "#{query}",
"variables" => ""
}
end
def graphql_query(conn, options) do
conn
2020-01-26 20:34:25 +01:00
|> post("/api", build_query(options[:query], Keyword.get(options, :variables, %{})))
|> json_response(200)
end
defp build_query(query, variables) do
%{
"query" => query,
"variables" => variables
}
end
end