Closed bjunc closed 7 years ago
I'm not sure I understand. Absinthe.Ecto doesn't explicitly use the primary key, or any other key at all. It relies entirely on your Ecto associations.
Thanks for getting back to me @benwilson512. I believe this was user error. I was attempting to handle associations from a database that started its life as Drupal; which has a mixture of unconventional primary keys and foreign keys.
To simplify things, I created a test scenario that required custom foreign keys, and all went well (eerily well, actually). It looks something like this (loosely mimicking Facebook's Post Graph API):
# ecto schema
schema "posts" do
field :message, :string
belongs_to :from, User, foreign_key: :from_user_id
belongs_to :to, User, foreign_key: :to_user_id
timestamps()
end
# graphql types
object :user do
field :id, :id
field :email, :string
field :first_name, :string
field :last_name, :string
field :wall, list_of(:post), resolve: assoc(:wall)
end
object :post do
field :id, :id
field :message, :string
field :from, :user, resolve: assoc(:from)
end
# graphql query
{
user (id: 1) {
wall {
message
from {
firstName
lastName
}
}
}
}
This results in two queries (one for posts, and one for users). Awesome!
Cool!
@bjunc hello, I'm trying something similar, how did you define your "users" schema?
It appears that the association is stitching together the field name and custom
@primary_key
, but ignoringforeign_key
.