Git Product home page Git Product logo

Comments (4)

benwilson512 avatar benwilson512 commented on June 19, 2024

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.

from absinthe_ecto.

bjunc avatar bjunc commented on June 19, 2024

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!

from absinthe_ecto.

benwilson512 avatar benwilson512 commented on June 19, 2024

Cool!

from absinthe_ecto.

rmap96 avatar rmap96 commented on June 19, 2024

@bjunc hello, I'm trying something similar, how did you define your "users" schema?

from absinthe_ecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.