ash-project / ash_hq

The Ash Framework homepage and documentation site.
MIT License
46 stars 25 forks source link

Build code examples on top of the Helpdesk app from the Get Started guide #92

Open Exadra37 opened 1 year ago

Exadra37 commented 1 year ago

Show where you found the issue

I have followed the Get Started guide to build the Helpdesk app and then followed the Whats next section where we have a link to learn how to use Code interfaces.

While I perfectly understood how to use the define_for , because it builds on top of the Helpdesk app, I wasn't able to grasp how to use the define_interface, because the example for it doesn't build on top of the Helpdesk app.

Share the problematic documentation

define_for and define_interface

Notice how we included a specific Api module using define_for above. Without this, no functions will be defined in the resource. This is because you might want to define the interface for multiple resources in a single module. While we encourage the use of define_for Api , it is not the only way to do it. You could also do something like this:


defmodule MyApp.MyApi.Interface do
 require Ash.CodeInterface

 Ash.CodeInterface.define_interface(MyApp.MyApi, MyApp.Resource1)
 Ash.CodeInterface.define_interface(MyApp.MyApi, MyApp.Resource2)
end

And then call functions on MyApp.MyApi.Interface instead. 
`

Additional context

It would be awesome if all the docs code examples would build on top of the HelpDesk app.

zachdaniel commented 1 year ago

Great idea :D

Exadra37 commented 1 year ago

Can you please give me an example of how to use define_interface with the Helpdesk app?

zachdaniel commented 1 year ago

Hey there! Sorry it took me a while to get to this. I responded on discord with an example :)