E5C3 GitHub - juffalow/express-graphql-example at 1.4.0 · GitHub
[go: up one dir, main page]

Skip to content

juffalow/express-graphql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  }
}

About

Example project how to use Express and GraphQL. You can find working example with frontend at https://quotes.juffalow.com

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

0