GraphQL v0.3.2 GraphQL

An Elixir implementation of Facebook’s GraphQL.

This is the core GraphQL query parsing and execution engine whose goal is to be transport, server and datastore agnostic.

In order to setup an HTTP server (ie Phoenix) to handle GraphQL queries you will need:

Examples for Phoenix can be found:

Here you’ll find some examples which can be used as a starting point for writing your own schemas.

Other ways of handling queries will be added in due course.

Execute a Query on the Schema

First setup your schema

iex> defmodule TestSchema do
...>   def schema do
...>     %GraphQL.Schema{
...>       query: %GraphQL.Type.ObjectType{
...>         name: "RootQueryType",
...>         fields: %{
...>           greeting: %{
...>             type: %GraphQL.Type.String{},
...>             resolve: &TestSchema.greeting/3,
...>             description: "Greeting",
...>             args: %{
...>               name: %{type: %GraphQL.Type.String{}, description: "The name of who you'd like to greet."},
...>             }
...>           }
...>         }
...>       }
...>     }
...>   end
...>   def greeting(_, %{name: name}, _), do: "Hello, #{name}!"
...>   def greeting(_, _, _), do: "Hello, world!"
...> end
...>
...> GraphQL.execute(TestSchema.schema, "{ greeting }")
{:ok, %{data: %{"greeting" => "Hello, world!"}}}
...>
...> GraphQL.execute(TestSchema.schema, ~S[{ greeting(name: "Josh") }])
{:ok, %{data: %{"greeting" => "Hello, Josh!"}}}

Summary

Functions

Execute a query against a schema (with validation)

Execute a query against a schema (without validation)

Functions

execute(schema, query, root_value \\ %{}, variable_values \\ %{}, operation_name \\ nil)

Execute a query against a schema (with validation)

# iex> GraphQL.execute(schema, "{ hello }")
# {:ok, %{hello: world}}

Deprecation warning: This will be replaced in a future version with the function signature for execute_with_opts/3.

execute_with_opts(schema, query, opts \\ [])

Execute a query against a schema (with validation)

# iex> GraphQL.execute_with_opts(schema, "{ hello }")
# {:ok, %{hello: world}}

This is the preferred function signature for execute and will replace execute/5.

execute_without_validation(schema, query, opts)

Execute a query against a schema (without validation)

# iex> GraphQL.execute(schema, "{ hello }")
# {:ok, %{hello: world}}