Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.09k stars 296 forks source link

connecting a postgres db to persist data #109

Closed agarwalchaitanya closed 3 years ago

agarwalchaitanya commented 3 years ago

Hi, Just started working with DGS and relatively new to Spring too. I wanted to connect a postgres db to persist data but am not sure how to. Any leads on this would be appreciated.

paulbakker commented 3 years ago

A DGS is basically also just a Spring Boot app. Although there are other good options, the easiest way is probably to use Spring Data. There is lots of documentation available here: https://spring.io/projects/spring-data, and there are lots of videos available online as well.

Since this isn't really a DGS question I'm closing the issue, but I hope this helps you get on track at least!

agarwalchaitanya commented 3 years ago

I'm not sure how to map schemas to data entities. A small example or a code snippet would help.

paulbakker commented 3 years ago

It depends on a lot of other choices in the tech stack. For example, there are many different frameworks for ORM (Object Relational Mapping), so it's not really possible to give a one-size-fits-all answer. You could use DGS codegen to generate Java classes from the GraphQL schema, and use something like spring-data-jdbc to map those to a database.

agarwalchaitanya commented 3 years ago

Got you. That should work. Thanks :)