irrigator

irrigator

GraphQL, Ecto and Database - Three layers of data abstraction

Recently I’m learning GraphQL by reading Craft GraphQL APIs in Elixir with Absinthe. So far everything makes sense, but the overlapping of three data layers - GraphQL, Ecto and Database schemas - concerns me in some way. Surely they operate at relatively different levels, and keeping them separate adds a lot of flexibility to your system. But the cost is also pretty high. Not only are there much duplication among these three layers (type definitions and some business logic), you also need to think about putting which portion to which layer, if not implement it more than once. The most prominent example is validation.

The situation reminds of the Phoenix context, which also asks for a deep thinking about design. For those who are using GraphQL with Ecto, what’s your take on this?

Most Liked

peerreynders

peerreynders

Phoenix contexts acknowledge that there are designs beyond CRUD. In CRUD applications the shape of the data in the page on the front end tends to dictate the shape of the data that is stored in the database. This is the hallmark of implementation coupling. Typically when you change something on one end that change ripples through to the other end (and any layers in between).

but the overlapping of three data layers - GraphQL, Ecto and Database schemas - concerns me in some way

That overlap may simply be a result of the technology being applied to an application with an “unsophisticated” domain - which wouldn’t be surprising if the entire point of the application is to clearly showcase how the technologies interact - without being obscured by complex application design concerns.

  • The shape of the data in the RDBMS is largely concerned with efficient and effective storage and retrieval of data the application typically uses - clearly the inserts, updates and queries influence the shape - but there may be optimization concerns to favour the performance characteristics of certain insert, update and query operations. That means that the capabilities of the RDBMS engine are going influence the shape of the data inside the database beyond the bare needs of the application.
  • Ecto brokers between the shape of the data needed by the application vs the shape of the data stored in the database. The shape of the data for the application is what you are primarily concerned with because that shape is influenced by the processing capabilities of the application.
  • GraphQL should be primarily concerned with the shape of the data that is needed by the client of the application (in the spirit of Consumer Driven Contracts). The application should typically hide certain implementation details from the client to stop the client becoming coupled to the implementation details of the application. Also the application could derive (aggregate) some information that doesn’t explicitly exist in the database for the purpose of exposing it to the client via GraphQL.
10
Post #4
OvermindDL1

OvermindDL1

What I think would be best for graphql projects is just have the database, have a graphql layer, and have both the API and Web Controllers access the GraphQL layer (so Controllers just call into the local GraphQL bit), that way it all goes through a single defined point that handles auth and all. :slight_smile:

StefanHoutzager

StefanHoutzager

Maybe you can find a discussion on some of the problems you found here? Five Common Problems in GraphQL Apps (And How to Fix Them)

Where Next?

Popular in Discussions Top

Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
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
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement