Giter VIP home page Giter VIP logo

sls-graphql-nest-api-base's Introduction

Description

This is an attempt to create a sample project that has following capabilities.

Installation

This was built using Node 18.x, Serverles framework 3.0. So please make sure you have those setup.

npm install

Running the app

DB Setup

# use docker to host postgres, make sure you dont have port 5432 already taken
# the below command uses postgres alphine (15.2)
docker compose up
CREATE DATABASE apibase;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Env file setup

Create a .env file and add a DATABASE_URL variable and set it to postgres database.

DATABASE_URL=postgresql://your_user_name:your_password@hostname:5432/apibase
NODE_ENV=DEV
IS_OFFLINE=TRUE

Make sure you run primsa migrations to create tables/populate the tables. You have to manually create the database. No script included for it.

# run npx generate
npx prisma generate

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# SLS local mode
$ npm run start:offline:dev

Serverless deploy

Create a default AWS profile. Make sure you set your region in profile and match it to to serverless.yml file.

This repo reads environment variables from AWS Parameter Store. So it requires to use default profile. There is a bug in SLS reading parameter store using other profiles.

If you don't want to read from ssm then remove it from serverless.yml file.

SLS requires good amount of permissions to deploy depending upon what AWS features you are using.

Here is a blog on what permissions you might need. https://serverlessfirst.com/create-iam-deployer-roles-serverless-app/

deploy

npm run deploy:dev

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Testing from your browser

After starting SLS locally go to http://localhost:3001/dev/graphql and test GraphQL calls.

query
{
  books
  {
    id
    title
  }
}# Write your query or mutation here

GraphQL Schema changes

This project uses GraphQL Code first approach. All the schema is defined in schema.gql file.

Edit the file to add new types, queries, or mutations. Implement those in proper handlers and try it.

Not working

Some things are not working.

  • I used paths in ts.config to see if I can reference using names as described in ts.config but that didn't work.
  • Using Apollo server / gateway.
  • Schema first graphql approach.

Credits

sls-graphql-nest-api-base's People

Contributors

nachimk avatar

Watchers

 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.