Closed zachdaniel closed 2 years ago
@benwilson512 if you have a few to look at this/let me know what it would take to get this over the line it would be great.
Also can you rebase off of main to remove the then
?
I think the then/2
is still in master? https://github.com/absinthe-graphql/dataloader/blob/master/test/dataloader/ecto_test.exs#L41
Ah apologies it got removed elsewhere. With the release of 1.14 we can probably move supported versions up to ~> 1.12
Yeah, that makes sense! I don't think me changing the matrix in my PR will change what builds for the PR (IIRC it uses main's github.yml file not the PR's github file, to avoid things like exfiltrating secrets). I'm happy to make that change in this PR, but it might make sense as a separate PR.
Do we feel like requiring a major version update is acceptable for this? Or do we want to find a more creative solution?
Hey @benwilson512 so if a major version number is out of the question, how about allowing application configuration to determine async? Its unideal because I'd have to ask my users to put this in their application env when testing with AshGraphql, but would be a potential compromise. i.e Application.get_env(:dataloader, dataloader, async?)
(I don't think we have their otp app here to look up the config there?)
@zachdaniel OK here is my current thinking. I am going to make a PR that basically just has dataloader accept an async: false
option that forces everything to be async false. Then folks can update their Dataloader.new
calls to set that option based on repo.in_transaction?
. This will be the backwards compatible patch version solution.
THEN we'll go ahead and get this PR across the finish line and this will be the 2.0 version that can handle async on a more granular level depending on the source.
Thoughts?
Sounds like a plan to me :D
I think from a code standpoint, I'm gonna go ahead and merge this into master, set the 2.0-pre version, and then checkout v1 and edit the code back to get rid of the protocol impl. That way your code gets attributed properly instead of me copying and pasting 85% of what you wrote.
In order to make dataloaders easier to use in test, I've added an
async?/1
function to the souurce protocol. Inasync_safely/3
(which is nowasync_safely/4
) we default toasync?: true
meaning this should be backwards compatible with any direct usage of that function.I've also added what would seem to me to be the proper default behavior for ecto and KV, which is that ecto will run synchronously if the repo is in a transaction, and KV is configurable at startup.
Feel free to tear it apart. This does seem pretty necessary for writing tests against absinthe in general, though :)
This is slightly orthoganal to #134 because its per-source
Addresses some if not all of #129