smahi
How to use ex_machina in umbrella apps
I have two apps restaurant_app and graphql_api_app in an umbrella.
I have ex_machina added as dependency to restaurant_app and properly configured there.
In graphql_api_app I want to use the same Factories from restaurant_app for fixtures.
How can i properly setup and configure my tests in graphql_api_app
Most Liked
cjbottaro
Who is Dave Lucia? I figured he would be the creator of ex_machina or something, but I check the GitHub page and he’s not on the list of contributors.
I also was not really a fan of using ex_machina, and tried to encourage people to just create records using plain Ecto functions instead… but I recently gave it another shot and it’s a bit easier to create associated records, so I’m giving it a shot again.
So every app in the umbrella just becomes a normal dir under lib in a normal mix project. We have several top level modules; not everything is nested under one module. I found that to be fine so far.
Then in runtime.exs we have sections like this…
if System.get_env("START_FOO") || System.get_env("START_ALL") do
config :my_app, Foo, start: true
end
if System.get_env("START_BAR") || System.get_env("START_ALL") do
config :my_app, Bar, start: true
end
And finally in lib/my_app/application.ex
...
children = [
# things you always want started
]
|> add_if_started(Foo)
|> add_if_started(Bar)
...
defp add_if_started(children, mod) do
start = Application.get_env(:my_app, mod, [])
|> Keyword.get(:start, false)
if start do
children ++ [module]
else
children
end
end
Then if you just want to startup foo, you can do:
START_FOO=1 mix run
Our original umbrella had over a dozen apps in it, but we rewrote it this way because we had lots of circular dependency problems. Our mix projects were filled with xref exceptions.
Also, it’s much easier to navigate this way. Much less config files and mix project files, etc.
cjbottaro
I mean, I find it kind of strange to just show a random tweet with zero context of someone saying they don’t like it. I just assumed it was supposed to be someone that I know.
No explanation or anything. Could have at least said something like, “While this question is specifically about how to use ex_machina, you should be aware that a lot of the community doesn’t recommend it.”
thojanssens1
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









