I have two tables, one in which I have two attributes that are foreign keys to the other table. Here my schema and migrations:
Schemas
schema "wire_types" do
field(:name, :string)
field(:description, string)
has_many(:input_wires, Api.Run, foreign_key: :input_wire_id)
has_many(:output_wires, Api.Run, foreign_key: :output_wire_id)
timestamps()
end
schema "runs" do
field(:start_at, :naive_datetime)
belongs_to(:input_wire, Api.WireType, foreign_key: :input_wire_id)
belongs_to(:output_wire, Api.WireType, foreign_key: :output_wire_id)
timestamps()
end
Migrations
def up do
create table(:wire_types) do
add(:name, :string)
add(:description, :string)
timestamps()
end
end
def up do
create table(:runs) do
add(:input_wire_id, references(:wire_types, on_delete: :nothing))
add(:output_wire_id, references(:wire_types, on_delete: :nothing))
add(:start_at, :naive_datetime)
timestamps()
end
create index(:runs, [:input_wire_id])
create index(:runs, [:output_wire_id])
end
The question
My question is, how must I define my object type
s? in order to do the following query:
{
wireTypes{
name
runs{
id
}
}
}
Right now I get Ecto.QueryError
because it is trying to find wiretype_id
which does not exist in my runs
table. How would you all suggest that I define this problem?
My current objects
are as follows:
object :run do
field(:id, :id)
field(:start_at, :naive_datetime)
field(:input_wire, :wire_type, resolve: assoc(:input_wire))
field(:output_wire, :wire_type, resolve: assoc(:output_wire))
end
object :wire_type do
field(:id, :id)
field(:name, :string)
field(:description, :string)
field(:runs, list_of(:run)) do
resolve(&App.RunResolver.all/3)
end
end