Packages

This module was made as a wrapper for the data api used in Betty Blocks. This package aims to allow you to make a graphql request using a single function.

Current section

Files

Jump to
betty_gql lib Queries data_queries.ex
Raw

lib/Queries/data_queries.ex

defmodule BettyGql.Queries.DataQueries do
@doc """
Generates the query to retrieve all objects of a given type
"""
def all_query(type, fields, filter) do
"""
{
all#{upcaseFirst type}(where: {#{filter}}){
results{
#{for x <- fields do
"#{x}\n "
end}
}
}
}
"""
end
def one_query(type, fields, filter) do
"""
{
one#{upcaseFirst type}(where: {#{filter}}){
#{for x <- fields do
"#{x}\n "
end}
}
}
"""
end
defp upcaseFirst(<<first::utf8, rest::binary>>), do: String.upcase(<<first::utf8>>) <> rest
end