Hi, I have an umbrella project with 4 different apps:
- Messenger: Handles email, push notifications, etc
- Data: Ecto Repo, schemas and queries
- Core: exposes services, handles authorization, depends on Data and Messenger apps.
- API: Phoenix app, already handles some REST endpoints and authentication. Depends con Core app.
I’m trying to add Absinthe to the project, I’m currently reading the Craft GraphQL APIs in Elixir with Absinthe book by @benwilson512 and looked at some projects with an implementation. However I haven’t find an example of how to organize code under an umbrella project.
In this particular project a request will be handled something like this:
API.Router
|> API.Plug.Authenticate
|> API.MyModelController
|> Core.MyModelService (Authorization, limiting, notifications)
|> Data.MyModelQueries
|> Messenger.send_something_if_needed
With this model, It’s pretty obvious where to put everything, each app has well defined boundaries, but adding Absinthe and it’s ecosystem to the mix seems a little confusing.
Firstly, where should I add each dependency?
absinthe
and absinthe_plug
belong to the API app, but what about dataloader
or absinthe_ecto
? should they go inside the Data app?
The problem is that these projects all seem very tied to each other, and looks counter intuitive to spread them across different apps.
The problem arises if I add them all to the API app since I don’t want (and is a bad practice) to alias/call Data or Ecto related modules from it, since its not a direct dependency.
Next, where should resolvers live? Is it a good idea to put them in the API app just like controllers and call the same services REST endpoints use from Core app?
Or should they live inside the Core app itself? (I’ve seen projects where resolvers are tied to contexts and not to the web side)
It’s the first time I’m working with Graphql so maybe I’m missing something?
Using the example above, how a Graphql request should look like starting from the router?
Any guidance in which direction to go will be appreciated.