Skip to content

A simple api services using prisma, typescript and graphql

Notifications You must be signed in to change notification settings

mframadann/typescript-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an image ExpressJS Prisma GraphQL Typescript

Simple GraphQL api implementation.

Simple GraphQL implementation, built using GraphQL, Prisma ORM, Typescript And ExpressJS.

Instalations

installing the dependencies:

$ npm install

push prisma schema to database:

$ npx prisma db push

with building:

$ npm run build
$ npm start

or without building:

$ npm run dev

Usage

Open http://localhost:yourport/graphql in your browser and creating a new user and profile data

mutation {
  createUsers(
    userInputs: {
      firstName: "Shina" 
      lastName: "Mahiru" 
      gender: "Female" 
      dateOfBirth: "2003-12-05" 
      emailAddress: "[email protected]" 
      password: "Password" 
    }
  ){
    ##your selected fileds. for example:
    email_address
    profile {
      first_name
      last_name
    }
  }
}

Getting all users data:

query {
  ## your queries name. for example: 
  users {
    ## select the fields you want. for example
    user_id
    email_address
  }
}

and server will be give a responses:

{
  "data": {
    "users": [
      {
        "user_id": "3",
        "email_address": "[email protected]",
      },
      {
        "user_id": "4",
        "email_address": "[email protected]",
      },
      {
        "user_id": "5",
        "email_address": "[email protected]",
      }
    ]
  }
}

Getting all users data with profile:

query {
  ## your queries name. for example: 
  users {
    ## select the fields you want. for example
    user_id
    email_address
    profile {
      first_name
      last_name
      gender
    }
  }
}

server will give a responses:

{
  "data": {
    "users": [
      {
        "user_id": "3",
        "email_address": "[email protected]",
        "profile": {
          "first_name": "Shina",
          "last_name": "Mahiru",
          "gender": "Female"
        }
      },
      {
        "user_id": "4",
        "email_address": "[email protected]",
        "profile": {
          "first_name": "Tachibana",
          "last_name": "Kanade",
          "gender": "Female"
        }
      },
      {
        "user_id": "5",
        "email_address": "[email protected]",
        "profile": {
          "first_name": "Kagari",
          "last_name": "Ayaka",
          "gender": "Female"
        }
      }
    ]
  }
}

Get user by id with profile

mutation {
  findUserById(
    userInputs: { user_id : 3}
  ){
    ## select the fields you want. for example
    email_address
    profile {
      first_name
      last_name
      last_updated
    }
  }
}

server will give a response:

{
  "data": {
    "findUserById": {
      "email_address": "[email protected]",
      "profile": {
        "first_name": "Shina",
        "last_name": "Mahiru",
        "last_updated": "2023-01-31T03:27:53.217Z"
      }
    }
  }
}

Get profiles data with the user:

query {
  ## your queries name. for example: 
  profiles {
    ## select the fields you want. for example
    first_name
    last_name
    gender
    last_updated
    user {
      email_address
      created_at
    }
  }
}

server will give a response:

{
  "data": {
    "profiles": [
      {
        "first_name": "Shina",
        "last_name": "Mahiru",
        "gender": "Female",
        "last_updated": "2023-01-31T03:27:53.217Z",
        "user": {
          "email_address": "[email protected]",
          "created_at": "2023-01-31T03:27:53.217Z"
        }
      },
      {
        "first_name": "Tachibana",
        "last_name": "Kanade",
        "gender": "Female",
        "last_updated": "2023-01-31T04:19:07.267Z",
        "user": {
          "email_address": "[email protected]",
          "created_at": "2023-01-31T04:19:07.267Z"
        }
      },
      {
        "first_name": "Kagari",
        "last_name": "Ayaka",
        "gender": "Female",
        "last_updated": "2023-01-31T04:19:52.695Z",
        "user": {
          "email_address": "[email protected]",
          "created_at": "2023-01-31T04:19:52.695Z"
        }
      }
    ]
  }
}

visit https://graphql.org for more documentations & Click this to connect me in insragram. thank you:D

About

A simple api services using prisma, typescript and graphql

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published