Current section

Files

Jump to
graphql lib graphql.ex
Raw

lib/graphql.ex

defmodule GraphQL do
@moduledoc ~S"""
The main GraphQL module.
The `GraphQL` module provides a
[GraphQL](http://facebook.github.io/graphql/) implementation for Elixir.
## Execute a query
Execute a GraphQL query against a given schema / datastore.
# iex> GraphQL.execute schema, "{ hello }"
# {:ok, %{hello: "world"}}
"""
@doc """
Execute a query against a schema.
# iex> GraphQL.execute(schema, "{ hello }")
# {:ok, %{hello: world}}
"""
def execute(schema, query, root_value \\ %{}, variable_values \\ %{}, operation_name \\ nil) do
case GraphQL.Lang.Parser.parse(query) do
{:ok, document} ->
case GraphQL.Execution.Executor.execute(schema, document, root_value, variable_values, operation_name) do
{:ok, response} -> {:ok, %{data: response}}
{:error, errors} -> {:error, errors}
end
{:error, errors} ->
{:error, errors}
end
end
end