Coder Social home page Coder Social logo

loopback-postgresql-graphql's Introduction

LoopBack 4 PostgreSQL GraphQL Boilerplate

A boilerplate/starter project for quickly building GraphQL APIs using Node.js, LoopBack 4 and PostgreSQL.

Prerequisites

  • Node (built with 19, but should work on lower)
  • PostgreSQL (locally, externally or docker)

Setup

Clone the repository

git clone [email protected]:thekeogh/loopback-postgresql-graphql.git

Install the dependencies

npm install

Create a local .env

touch .env.development.local

Copy the values (only the ones you need to change) from the .env.development file to this new file, for example:

# Database
DB_USER=joe
DB_PASSWORD=mysuperpassword
DB_DATABASE=loopback

More details on the environment config below.

Migrate the database

See the database section for this step.

Start the API

npm start
# or for dev (using tsc-watch)
npm run dev

You should now see the relevant URLs in your terminal.

Database

Although designed with PostgreSQL in mind, there is no reason why you cannot change the datasource to another (e.g. MariaDB, Oracle, Mongo etc), it is LoopBack after all, and has many drivers. But we use PostgreSQL for this API

Once you have entered your database credentials above, PostgreSQL is ready to go out-the-box. There is an example user model in the models/ folder ready to go, to migrate this:

NODE_ENV=development npm run migrate

Now check your database and you should see a user table.

GraphQL

GraphQL is built in to the service via the openapi-to-graphql and graphql-http libraries. This means, that GraphQL will run on the same port/url as your OAS3 RESTful API. For example:

RESTful: https://localhost:3200
GraphQL: https://localhost:3200/graphql

GraphiQL is not currently supported.

Environment

dotenv-flow is used out the box, so please read the documentation over there for more on this.

It's also advisable to add any new env variables to the src/env.d.ts file to allow TypeScript insight.


LoopBack

loopback-postgresql-graphql's People

Contributors

thekeogh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.