kxkannan
Using GrapphQL api for web app vs. directly calling module functions
Hello,
We have a pretty mature GraphQL API that our front-end iOS app uses to communicate with the backend to authenticate, query and mutate. There is also another Python SDK layer that uses this GraphQL API.
Now we are planning to develop our Web app using Phoenix framework and the question is should we be using the same GraphQL API to interact with the server or make calls directly to the Module.functions (i.e User.login(email, password) instead of calling the login GraphQL api. I am leaning towards using the GraphQL api for all the query/mutations for the Webapp as I am worried about session management, cookies, caching etc that comes into play in a typical web app.
Are there any pros/cons to consider? What do people generally use?
First Post!
mindok
We built the web application first and directly access modules, and use GraphQL to server to iOS so a slightly different scenario.
I would be personally be inclined to talk directly to the module functions and bypass a whole load of overhead of handling the GraphQL call, encoding the response, decoding the response, rebuilding structs for the web application to interact with - it will make coding harder and the system less performant to have all those extra, unnecessary layers in there.
Could you elaborate on your worries about session management, cookies, caching etc that you think using GraphQL will solve for?
Most Liked
mindok
Hi @kxkannan,
Transferring credentials from the conn to the socket is discussed in the LiveView docs here:
Security considerations — Phoenix LiveView v1.2.5.
There is a pretty decent explanation of how it all hangs together here: Securing Your Phoenix LiveView Apps | AppSignal Blog
Basically, the “session” parameter in the mount callback in your liveview should contain the credentials, and you transfer the credentials to the liveview socket there. However, rather than do this across all liveviews, you can define a hook shared across them. The wire-up to connect a specific on_mount hook to a group of liveviews is done in the router using live_session.
Popular in Discussions
Other popular topics
Latest Phoenix Threads
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









