GithubHelp home page GithubHelp logo

tanfrank / express-graphql-sequelize-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juffalow/express-graphql-example

0.0 0.0 0.0 66 KB

Example project how to use Express, GraphQL and Sequelize

JavaScript 100.00%

express-graphql-sequelize-example's Introduction

Express, GraphQL and Sequelize example

out

How to run the project

Install dependencies :

yarn

# or

npm install

Edit config/config.json :

{
    "development": {
        "username": "root",
        "password": null,
        "database": "sequelize-example",
        "host": "127.0.0.1",
        "dialect": "mysql"
    },
    "test": {
        ...
    },
    "production": {
        ...
    }
}

Init and seed database :

sequelize db:migrate

sequelize db:seed:all

Run the project :

npm start

Open GraphiQL in your browser http://localhost:8088/graphql

Examples

Get list of authors:

query{
  authors{
    name
    last_name
  }
}

This will return only first 10 authors!

If you want to get another 10 authors:

query{
	authors(offset: 10){
    id
    name
  }
}

Or more than 10 authors:

query{
	authors(first: 20){
    id
    name
  }
}

Get name of author with ID = 4:

query{
	author(id:4){
    name
  }
}

Get list of quotes:

query{
	quotes{
    quote
  }
}

This will return only first 10 quotes!

If you want to get another 10 quotes:

query{
	quotes(offset: 10){
    id
    quote
  }
}

Or more than 10 quotes:

query{
	quotes(first: 20){
    id
    quote
  }
}

Add new author and get his ID:

mutation{
  createAuthor(author:{
    name:"Kent",
    last_name:"Beck"
  }) {
    id
  }
}

Add new author with some of his quotes:

mutation{
  createAuthor(author:{
    name:"Kent",
    last_name:"Beck",
    quotes:[
      {
        quote: "I'm not a great programmer; I'm just a good programmer with great habits."
      },
      {
        quote: "Do The Simplest Thing That Could Possibly Work"
      }
    ]
  }) {
    id
  }
}

Delete specific quote ( quote with id 1 ) and return its id and quote text:

mutation{
	deleteQuote(id: 1){
    id
    quote
  }
}

Update ( change ) specific quote :

mutation{
	updateQuote(id: 1, quote: "New version of this quote!"){
    id,
    quote
  }
}

express-graphql-sequelize-example's People

Contributors

juffalow avatar thinkingmik 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.