Giter VIP home page Giter VIP logo

express-graphql-example's Introduction

Express, GraphQL example

License

out

How to run the project

Install dependencies :

yarn

# or

npm install

Update src/database.js file with your credentials:

import Knex from 'knex';

export default new Knex({
  client: 'mysql2',
  connection: {
    host : '127.0.0.1',
    user : 'root',
    password : '',
    database : 'express-graphql-example'
  }
});

Init the database. You can find the SQL script int database.sql.

Run the project :

npm start

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

Examples

Get list of authors (it will return only first 10 authors!):

query {
  authors {
    edges {
      node {
        id
        _id
        firstName
        lastName
      }
    }
  }
}

Filter authors based of first name, also return total number of such authors:

query {
  authors(firstName: "Robert") {
    totalCount
    edges {
      node {
        id
        _id
        firstName
        lastName
      }
    }
  }
}

Order authors by first name and last name:

query {
  authors(orderBy:[
    {
      field:FIRST_NAME
      direction:ASC
    }
    {
      field:LAST_NAME
      direction:ASC
    }
  ]) {
    edges {
      cursor
      node {
        _id
        firstName
        lastName
      }
    }
  }
}

Get name of author with ID = 4:

query {
  author(id: 4) {
    id
    _id
    firstName
    lastName
  }
}

Get list of quotes:

query {
  quotes {
    edges {
      node {
        id
        _id
        quote
      }
    }
  }
}

Create new author:

mutation {
  createAuthor(input:{
    firstName:"Kent"
    lastName:"Beck"
  }) {
    id
    _id
    firstName
    lastName
  }
}

Update existing author:

mutation {
  updateAuthor(input:{
    id: 1
    firstName: "JOHN"
    lastName: "JOHNSON"
  }) {
    id
    _id
    firstName
    lastName
  }
}

Old version

Here is a link to an old version, that used sequelize and did not use connections:

License

MIT license

express-graphql-example's People

Contributors

juffalow avatar thinkingmik avatar

Watchers

James Cloos avatar  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.