kxkannan

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

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

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.

Where Next?

Popular in Discussions Top

pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18634 126
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

We're in Beta

About us Mission Statement