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

Added Dataloader.has_source? so registered sources can be checked #28

Conversation

declaneugeneleekennedy
Copy link

While writing some code to add multiple sources to a loader, I noticed that after a source is added subsequent calls to add_source would overwrite the existing source which makes sense. But I wanted to be able to be defensive about it, so I've added a function to check before potentially overwriting an existing source.

def has_source?(%{sources: sources}, source) do
Map.has_key?(sources, source)
end

defp get_source(loader, source_name) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead we should just make get_source not private here? Then you could still do if !Dataloader.get_source etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning behind using a separate function was that get_source will currently raise, and it feels a bit unfriendly to make people wrap their checks in a catch. That said, is there any reason that it needs to raise?

@benwilson512
Copy link
Contributor

The struct is typespeced and sources is documented there. Accessing directly is just fine, I don't think we need an accessor function at this time.

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.

None yet

2 participants