Coder Social home page Coder Social logo

zainxyz / graphql-cars Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 6 KB

A sample GraphQL server running with a json-server to provide testing environment for queries and mutations.

License: MIT License

JavaScript 100.00%
graphql nodejs json-server jsonschema schema database cars es6 es6-javascript es6-promises

graphql-cars's Introduction

graphql-cars

A sample GraphQL server running with a json-server to provide testing environment for queries and mutations.

All written in ES6, transpiled via Babel.

How to start?

Install all of the dependencies via:

npm i

Open up two tabs in Terminal (or 2 CMD Prompts).

  • 1 will be used for the Node Server
  • 1 will be used for the JSON Server

To start the Node Server simply run:

npm start

To start the JSON Server simply run:

npm run json:server

Test it out!

GraphiQL

This is our GraphQL Playground, it helps us run queries on our database leveraging the GraphQL Server we've put together. Simply visit the following URL:

http://localhost:9000/graphql

Our Database

This is our JSON powered server to which we can send all sorts of HTTP requests (GET, PUT, PUSH, PATCH, DELETE). To access our DB, visit the following URL:

http://localhost:3000/

Send some sample queries to our GraphiQL

Here is a sample Query that works well (note it has some fragments, etc.):
query findCar {
  db11: car(id: "db11") {
    ...carDetails
  }
  huracan: car(id: "huracan") {
    ...carDetails
  }
  maserati: manufacturer(id: "maserati") {
    ...manufacturerDetails
  }
}

fragment carDetails on Car {
  name
  year
  hp
  price
  manufacturer {
    name
    founded
    founder
  }
}

fragment manufacturerDetails on Manufacturer {
  name
  founded
  founder
  headquarters
  cars {
    name
    hp
    price
    manufacturer {
      name
    }
  }
}

Output of the previous query should be:

{
  "data": {
    "db11": {
      "name": "GranTurismo",
      "year": 2017,
      "hp": 444,
      "price": "$132,825",
      "manufacturer": {
        "name": "Maserati S.p.A.",
        "founded": 1914,
        "founder": "Alfieri Maserati"
      }
    },
    "huracan": {
      "name": "Huracan",
      "year": 2015,
      "hp": 560,
      "price": "$199,800",
      "manufacturer": {
        "name": "Automobili Lamborghini S.p.A.",
        "founded": 1963,
        "founder": "Ferruccio Lamborghini"
      }
    },
    "maserati": {
      "name": "Maserati S.p.A.",
      "founded": 1914,
      "founder": "Alfieri Maserati",
      "headquarters": "Modena, Italy",
      "cars": [
        {
          "name": "GranTurismo",
          "hp": 444,
          "price": "$132,825",
          "manufacturer": {
            "name": "Maserati S.p.A."
          }
        }
      ]
    }
  }
}
Here is a sample Mutation to edit a car:
mutation {
  editCar(id: "huracan", hp: 3000, manufacturerId: "lamborghini") {
    name
    engine
    hp
    manufacturer {
      name
      headquarters
    }
  }
}

Go Crazy with Cars and GraphQL :)

graphql-cars's People

Contributors

zainxyz avatar

Stargazers

 avatar

Watchers

 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.