Ectograph

Ectograph is a set of utility functions for using Ecto in combination with GraphQL (specifically this graphql library for Elixir).

defp deps do
  [
    { :ecto, "~> 2.0.0-rc.5" },
    { :graphql, "~> 0.2.0" }
  ]
end

Features

How to use

Schemas
defmodule Schemas.Quote do
  use Ecto.Schema

  schema "quotes" do
    field :quote, :string
    field :author, :string

    timestamps
  end

end

Ectograph.Schema.cast_schema(Schemas.Quote, :ecto_to_graphql)
# %GraphQL.Type.ObjectType{ name: "quotes", fields: %{ quote: %{ type: ... }, ... }}
Types
Ectograph.Type.cast_type(:string, :ecto_to_graphql)
# %GraphQL.Type.String{}

Ectograph.Type.cast_type({ :array, :integer }, :ecto_to_graphql)
# %GraphQL.Type.List{ ofType: :integer }

Ectograph.Type.cast_type(%GraphQL.Type.String{}, :graphql_to_ecto)
# :string

Ectograph.Type.cast_type(%GraphQL.Type.List{ ofType: :integer }, :graphql_to_ecto)
# { :array, :integer }
Example

You can find a working example at https://github.com/icidasset/key_maps.
The crucial bit is located at lib/graphql/definitions.ex.

Installation

If available in Hex, the package can be installed as:

  1. Add ectograph to your list of dependencies in mix.exs:

    def deps do

     [{:ectograph, "~> 0.0.8"}]

    end

  2. Ensure ectograph is started before your application:

    def application do

     [applications: [:ectograph]]

    end

To do

Missing features:

Things I haven't tried yet:

Ecto types that still have to be implemented: