liveforeverx / dlex

Dlex is a gRPC based client for the Dgraph database.
Apache License 2.0
78 stars 21 forks source link

Request for supporting associations and resolvers #47

Open goravbhootra opened 4 years ago

goravbhootra commented 4 years ago

Hi,

This is a request for supporting associations and resolvers. Something like following:

defmodule Person do
  use Dlex.Node
  @derive {Phoenix.Param, key: :uid}

  import Ecto.Changeset

  schema "persons" do
    field :name,      :string
    field :age,       :integer
    field :works_at,  :uid, model: Company
    field :company_count, :integer, virtual: true, resolve: "count(works_at)"
  end

  ...

Thanks, Gorav

liveforeverx commented 4 years ago

Hi!

Thank you for request! 👍

Are there any analogy functionality to resolve in ecto? I would like to see find something similar in ecto, before continue on this.

goravbhootra commented 4 years ago

There are references from Absinthe: https://hexdocs.pm/absinthe/Absinthe.Resolution.html https://hexdocs.pm/absinthe/query-arguments.html https://hexdocs.pm/absinthe/ecto.html https://www.howtographql.com/graphql-elixir/2-queries/

Could not find anything directly from ecto

goravbhootra commented 4 years ago

Also, how do we handle associations? has_many and belongs_to which ecto supports?

Could we have something like:

defmodule App.Person do
  ...
  has_many :lands, [:uid]
  ...
end

defmodule App.Land do
  ...
  belongs_to :person, :uid
  ...
end

AND

defmodule App.Land do
  ...
  belongs_to :owner, :uid, type: App.Person, reverse: true
  ...
end