Skip to content

An example Express based app implementing a GraphQL API using MySQL as its datastore

License

Notifications You must be signed in to change notification settings

sejoalfaro/nodejs-graphql-mysql-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS graphQL MySQL example

This is a simple experimental example of how to match graphql-js and MySQL for the implementation of a GraphQL API.

  • This project requires a version of NodeJS with support for async-await

Getting Started

# clone the project
git clone git@github.com:YuLeven/nodejs-graphql-mysql-example.git
cd nodejs-graphql-mysql-example

# Install dependencies
npm install

# Run the server
PORT=8080 MYSQL_DB_USER=root MYSQL_DB_NAME=exapp MYSQL_DB_PASSWORD=secret MYSQL_DB_ADDRESS=localhost MYSQL_DB_POOL_SIZE=10 npm start

# Access GraphQLi
http://localhost:8080/graphql

Please remember to export the example SQL schema located in ./sql/exapp.sql

Example operations

Show all bacons

{
  bacons {
    id,
    type,
    price
  }
}

Filter bacons by price

{
  bacons(price: 25) {
    id,
    type,
    price
  }
}

Gets a bacon by its ID

{
  bacon(id: 1) {
    id,
    type,
    price
  }
}

Adds a new bacon

mutation {
  addBacon(type: "truffy", price: 99) {
    id,
    type
    price
  }
}

Updates a bacon

mutation {
  updateBacon(id: 1, type: "musky", price: 1) {
    id,
    type
    price
  }
}

License

MIT

About

An example Express based app implementing a GraphQL API using MySQL as its datastore

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 88.4%
  • TSQL 11.6%