GraphQL

The main GraphQL module.

The GraphQL module provides a GraphQL implementation for Elixir.

Parse a query

Parse a GraphQL query

iex> GraphQL.parse "{ hello }"
{:ok, %{definitions: [
  %{kind: :OperationDefinition, loc: %{start: 0},
    operation: :query,
    selectionSet: %{kind: :SelectionSet, loc: %{start: 0},
      selections: [
        %{kind: :Field, loc: %{start: 0}, name: "hello"}
      ]
    }}
  ],
  kind: :Document, loc: %{start: 0}
}}

Execute a query

Execute a GraphQL query against a given schema / datastore.

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

Summary

Execute a query against a schema

Parse the input string into a Document AST

Tokenize the input string into a stream of tokens

Functions

execute(schema, query)

Execute a query against a schema.

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

Parse the input string into a Document AST.

iex> GraphQL.parse("{ hello }")
{:ok,
  %{definitions: [
    %{kind: :OperationDefinition, loc: %{start: 0},
      operation: :query,
      selectionSet: %{kind: :SelectionSet, loc: %{start: 0},
        selections: [
          %{kind: :Field, loc: %{start: 0}, name: "hello"}
        ]
      }}
    ],
    kind: :Document, loc: %{start: 0}
  }
}
tokenize(input_string)

Tokenize the input string into a stream of tokens.

iex> GraphQL.tokenize("{ hello }")
[{ :"{", 1 }, { :name, 1, 'hello' }, { :"}", 1 }]