DEV Community

Wanna play with GraphQL on an existing database

Daniel da Rocha on August 24, 2018

I spend some time earlier this year building a REST-API for a personal app project (Vue in the frontend, Python + Flask + Postgres for the backend ...
Collapse
 
benoitscherrer profile image
benoitscherrer

We tried Hasura two weeks ago and i m shocked how amazing/easy it was with our existing postgres database.

Just had to pull and run a docker image, provide auth to postgres, press two buttons and that was it. All the mutations/etc were generated for our db (some tables have like 60+ columns) with "where" filters, operators for strings, integer, bolean expressions, etc...

Definitely worth a try

Collapse
 
patcito profile image
Patrick Aljord

+1 for Hasura. It even supports postgis and their discord support channel is amazing discordapp.com/invite/SwRFxa5

Collapse
 
erikthered profile image
Erik Nelson

I tried hooking up Prisma to an existing PostgreSQL DB a few months ago and it was way too many hoops to jump through. I think they're still working on improving that use case though.

Let us know if/when you find a good solution for this!

Collapse
 
danroc profile image
Daniel da Rocha

Quick follow-up after some weeks trying stuff out:

I decided to go all in with putting most of my business logic inside my database (Postgres, versioning using Sqitch), and using Postgraphile as the GraphQL API layer (this guide was essential to get started). I then use the Apollo Client on Vue (vue-apollo) to query and mutate my data.

I'm still in the middle of it, but loving it so far!

Collapse
 
joeschr profile image
JoeSchr

Thanks for posting this

Collapse
 
danroc profile image
Daniel da Rocha

Six months in, I would never look back. Once it "clicks", it is a joy to develop. I ditched Sqitch, though (ashamed to say I still did not implemented a db migration system....), and I am still figuring out how to best test my Postgres functions. However, more and more I rely on Postgraphile's auto-created methods to manipulate data on the server, so testing should be less of an issue in the future.

Thread Thread
 
joeschr profile image
JoeSchr

why did you ditch sqitch? lack of utility? I was looking forward to having finally found someone of continuous DB migration (like in laravel).

what's currently also stopping me from pulling the trigger on this, at some point in the future I maybe will wrap this project into electron to deploy it as standalone. and I'm not sure how lightweight, versatile PostgreSQL is on eg windows...

thanks for further elaborating btw!

Thread Thread
 
danroc profile image
Daniel da Rocha

It just felt it was holding me back on fast iterations, as my DB was relatively simple. My plan was to have a base version with all the tables I needed, then create a base migration and go from there. But I never did the "first migration" in the end. I know this will bite me in the ass later, so it is on my TODO list.

GraphQL is actually quite simple once you get the grips of it. I am also planning on trying to write my own schema in my next project, just for practice. You should give it a try, then maybe use SQLite for your Electron project?

Thread Thread
 
joeschr profile image
JoeSchr

You should give it a try, then maybe use SQLite for your Electron project?

Writing my own schema wouldn't be the problem, but I hope that graphile writes all the CRUD and other boilerplate resolvers for me which I hate to do over and over again

Collapse
 
ben profile image
Ben Halpern

I was an early adopter of GraphQL but haven't paid a lot of close attention since.

I can tell you that at the time I used GraphQL Ruby and it was a pretty simple process of mapping GraphQL queries to behavior/queries already available in the app.

PostGraphile looks like it sits lower in the stack and interfaces directly with the DB. To do it with more awareness of your app's context, looks like Graphene Python might do the trick.

Apollo looks like it cares more about the Vue side of things, so you'd probably use that in addition to whatever you're doing on the server.

I might not be fully caught up on GraphQL things, but that's my initial impression.

Collapse
 
danroc profile image
Daniel da Rocha

Apollo looks like it cares more about the Vue side of things, so you'd probably use that in addition to whatever you're doing on the server.

it seems Apollo originally does not have much to do Vue and has its own server and client tools. Apollo-Vue is an Apollo Client for a Vue application, which would then communicate with the Apollo Server.

I might want to ditch Python completely and keep everything within the Node environment, so it should be an interesting option...

Collapse
 
ben profile image
Ben Halpern

Yeah I must have been mistaken.

Node will probably have the best tooling and libs. If you're deadset on GraphQL and it's reasonable to change backends, Node seems like the right call.

Collapse
 
rhymes profile image
rhymes

I've played a tiny bit with GraphQL and Python and Graphene seems to be the way to go. I tried with Graphene Django though, there's also a tutorial for Flask here: docs.graphene-python.org/projects/...

Don't expect tons of documentation around :-D

Collapse
 
iamrorysilva profile image
Rory Silva • Edited

I've played with Adonis, Loobback 4, Strapi, and Hasura. +1 for Hasura. I'm not trashing the others but Hasura is looking like a solid solution for common needs. Besides the GraphQL UI, they've added database schema UI, data admin UI, hooks UI with events/response, roles/permissions to the data, and more.

Collapse
 
steveemmerich profile image
Steve Emmerich

Prisma could be a good option but as Erik Nelson mentioned it's still a bit of work. Depending on how much your backend is actually doing; it might be easier to move to Node and Apollo as Daniel da Rocha said. If you really don't need a server and just want a graphQL db you could tryout graph.cool it's a baas and they make Prisma.

Collapse
 
laueian profile image
Ian Laue

You can try a new open source tool called SwitchQL (github.com/SwitchQL/SwitchQL). I've been working on the project for a while.

You pass it your connection string and it returns everything you need to run a graphql server on top of an existing database. It also returns Apollo compliant client mutation and queries.

We only support Postgres at the moment. If you end up trying it out, please let me know what you think!