All Projects → icidasset → ectograph

icidasset / ectograph

Licence: MIT license
Ectograph is a set of utility functions for using Ecto in combination with graphql-elixir/graphql

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to ectograph

Rummage ecto
Search, Sort and Pagination for ecto queries
Stars: ✭ 190 (+555.17%)
Mutual labels:  ecto
absinthe error payload
Bridges the gap between Ecto and Absinthe for mutation payload
Stars: ✭ 102 (+251.72%)
Mutual labels:  ecto
algoliax
Algolia integration to elixir application
Stars: ✭ 38 (+31.03%)
Mutual labels:  ecto
Ex audit
Ecto auditing library that transparently tracks changes and can revert them.
Stars: ✭ 214 (+637.93%)
Mutual labels:  ecto
ecto erd
A mix task for generating Entity Relationship Diagram from Ecto schemas available in your project.
Stars: ✭ 173 (+496.55%)
Mutual labels:  ecto
prometheus-ecto
Prometheus.io collector for Elixir.Ecto
Stars: ✭ 74 (+155.17%)
Mutual labels:  ecto
Filtrex
A library for performing and validating complex filters from a client (e.g. smart filters)
Stars: ✭ 157 (+441.38%)
Mutual labels:  ecto
ecto profiler
Project for Ecto DB profiling
Stars: ✭ 16 (-44.83%)
Mutual labels:  ecto
fat ecto
Query mechanism for Ecto
Stars: ✭ 20 (-31.03%)
Mutual labels:  ecto
strong migrations
Catch unsafe migrations in your Elixir application
Stars: ✭ 58 (+100%)
Mutual labels:  ecto
Ecto mnesia
Ecto adapter for Mnesia Erlang term database.
Stars: ✭ 223 (+668.97%)
Mutual labels:  ecto
Params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters.
Stars: ✭ 239 (+724.14%)
Mutual labels:  ecto
query builder
Compose Ecto queries without effort
Stars: ✭ 56 (+93.1%)
Mutual labels:  ecto
Formex
A better form library for Phoenix
Stars: ✭ 206 (+610.34%)
Mutual labels:  ecto
phoenix pagination
Simple pagination for Ecto and Phoenix that uses plain EEx templates.
Stars: ✭ 20 (-31.03%)
Mutual labels:  ecto
Phoenix Ecto Encryption Example
🔐 A detailed example for how to encrypt data in a Phoenix (Elixir) App before inserting into a database using Ecto Types
Stars: ✭ 166 (+472.41%)
Mutual labels:  ecto
ecto shorts
Shortcuts for ecto
Stars: ✭ 81 (+179.31%)
Mutual labels:  ecto
music db
A playground for Ecto using a simple music database
Stars: ✭ 29 (+0%)
Mutual labels:  ecto
querie
Compose Ecto query from the client side
Stars: ✭ 20 (-31.03%)
Mutual labels:  ecto
ex operation
A library for making domain operations in Elixir
Stars: ✭ 33 (+13.79%)
Mutual labels:  ecto

Ectograph is a set of utility functions for using Ecto in combination with graphql-elixir/graphql.

{
  :ecto, "~> 2.0.2",
  :graphql, "~> 0.3.1"
}

Features:

  • Map a Ecto.Type to a GraphQL.Type
  • Map a Ecto.Schema to a GraphQL.Type.ObjectType
  • Provide extra GraphQL types, such as DateTime
  • Utilities to help build a GraphQL schema

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(Schemas.Quote)
# %GraphQL.Type.ObjectType{ name: "quotes", fields: %{ quote: %{ type: ... }, ... }}
Types
Ectograph.Type.cast(:string)
# %GraphQL.Type.String{}

Ectograph.Type.cast({ :array, :integer })
# %GraphQL.Type.List{ ofType: :integer }
Utilities
schema = %GraphQL.Schema{
  query: %GraphQL.Type.ObjectType{
    name: "Queries",
    description: "GraphQL Queries",
    fields: %{
      quotes: Ectograph.Definitions.build(Quote, :all, ~w()a),
      quote: Ectograph.Definitions.build(Quote, :get, ~w(id)a),
    },
  },
}

# BUILD FUNCTION:
# Quote   = Resolver module
# :get    = method on resolver that will be called
# ~w(id)a = List of fields that will be used as arguments

# NOTE:
# Either the resolver itself is an Ecto schema,
# or you define a function called 'ecto_schema' that
# returns the Ecto schema.

See the integration tests for a working example, and the docs for more info.

# Adding extra arguments to a query
Ectograph.Definitions.extend_arguments(
  put_field_aka_definition_here,
  %{ extra_argument: %{ type: %GraphQL.Type.String{} }}
)

# Adding extra fields to a query
Ectograph.Definitions.extend_type_fields(
  put_field_aka_definition_here,
  %{ extra_field: %{ type: %GraphQL.Type.Int{} }}
)

# Adding associations
Ectograph.Definitions.add_association(
  put_field_aka_definition_here,
  Resolver,
  :association_name,
  :multiple # or :single (default = :single)
)
Maps

How to use maps as arguments in mutations:

defmodule Example do
  use Ecto.Schema

  schema "examples" do
    field :attributes, :map
  end

  def create(_, args, _) do
    is_map? args[:attributes] # true
  end
end

schema = %GraphQL.Schema{
  mutation: %GraphQL.Type.ObjectType{
    fields: %{
      create: Ectograph.Definitions.build(Example, :create, ~w(attributes)a),
    },
  },
}

Query:

mutation _ {
  create (attributes: { example: "test" }) { attributes }
}

Query with variables:

mutation _ ($attributes: Map) {
  create (attributes: $attributes) { attributes }
}

Note: Apparently it doesn't matter which type you put there. Could be $attributes: Object too.

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.2.0"}] end

  2. Ensure ectograph is started before your application:

    def application do [applications: [:ectograph]] end

To do

Things that are missing or could be improved

  • Embedded schemas
  • Associations

Ecto types that still have to be implemented:

  • binary
  • decimal
  • date
  • time
  • composite types
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].