Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate id for schemas without primary key #173

Merged

Conversation

fuelen
Copy link
Contributor

@fuelen fuelen commented Aug 2, 2024

handles a case when embedded schema struct belongs to normal record, like

User
  embeds_one(:address, Address)

Address
  belongs_to(:country, Country)

@fuelen
Copy link
Contributor Author

fuelen commented Aug 2, 2024

@benwilson512 please let me know whether this approach OK, and you're ready to merge it, so I could add some tests

@benwilson512
Copy link
Contributor

Hi @fuelen can you elaborate a bit more? What sort of Dataloader.load call does this help with?

@fuelen
Copy link
Contributor Author

fuelen commented Aug 2, 2024

Hi @benwilson512
Sure 🙂

If we talk in terms of the schema example above, then I do the following GraphQL query

{
  users {
    address {
      country { name }
    }
}

the :address object is defined like this

object :address do
  field(:country, :country, resolve: dataloader(MyApp.Geography))
end

nothing special, the resolution of :country field is completely handled by dataloader, no custom options.

Let's say we have 2 users. One user doesn't have set a country in his address (country_id is null). I want to remind, that Address is an embedded schema. Because of this, primary key for embedded schema that doesn't have primary keys is always []. It means that [] will be used as an id for all Address structs. So, all addresses will fetch the same country. I noticed, that the first write wins, and depending on the order, all users will have the same country from DB or NULL.

@fuelen
Copy link
Contributor Author

fuelen commented Sep 2, 2024

Hey @benwilson512
Could you look into this?

@benwilson512
Copy link
Contributor

Hi @fuelen this seems fine, please just add a test.

handles a case when embedded schema struct belongs to a regular record
@fuelen fuelen force-pushed the handle_schemas_without_primary_key branch from 3361ad1 to f2b6a9c Compare September 3, 2024 09:54
@fuelen
Copy link
Contributor Author

fuelen commented Sep 3, 2024

Added a test

@fuelen
Copy link
Contributor Author

fuelen commented Sep 30, 2024

Hi @benwilson512
Could you merge this PR? 🙂

@benwilson512 benwilson512 merged commit 539356c into absinthe-graphql:main Sep 30, 2024
@benwilson512
Copy link
Contributor

Thanks!

@fuelen fuelen deleted the handle_schemas_without_primary_key branch October 1, 2024 11:36
@fuelen fuelen mentioned this pull request Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants