Coder Social home page Coder Social logo

nicholascrotty / fullstack-graphql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atulmy/fullstack-graphql

0.0 0.0 0.0 196 KB

Simple Fullstack GraphQL Application. API built with Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux to access the API. Writtten in ES6 using Babel + Webpack.

JavaScript 95.41% HTML 4.59%

fullstack-graphql's Introduction

logos

Fullstack GraphQL

Simple Demo Application

API built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL).

WebApp built with React + Redux.

Written in ES6 using Babel + Webpack.

๐Ÿ“ Features

  • List thoughts
  • Add thought
  • Delete thought
  • View single thought

โ–ถ๏ธ Running

  • Clone repo git clone [email protected]:atulmy/fullstack-graphql.git fullstack-graphql
  • Install NPM modules API cd api and npm install
  • Install NPM modules Webapp cd webapp and npm install
  • Modify /api/src/config/database.json for database credentials
  • Modify /api/src/config/config.json for API port (optional)
  • Modify /webapp/.env for webapp port (optional)
  • Run API cd api and npm start, browse GraphiQL at http://localhost:3000/
  • Run Webapp cd webapp and npm start, browse webapp at http://localhost:8000/

Sample API logs

[nodemon] starting `babel-node src/index.js --presets es2015,stage-2`
SETUP - Connecting database...
SETUP - Loading modules...
SETUP - GraphQL...
SETUP - Syncing database tables...
INFO - Database connected.
INFO - Database sync complete.
SETUP - Starting server...
INFO - Server started on port 3000.

๐Ÿ“ธ Screenshots

screenshot

Video: MOV

๐Ÿ— Core Structure

fullstack-graphql
  โ”œโ”€โ”€ api (api.example.com)
  โ”‚   โ”œโ”€โ”€ src
  โ”‚   โ”‚   โ”œโ”€โ”€ config
  โ”‚   โ”‚   โ”œโ”€โ”€ models
  โ”‚   โ”‚   โ”œโ”€โ”€ schema
  โ”‚   โ”‚   โ”œโ”€โ”€ setup
  โ”‚   โ”‚   โ””โ”€โ”€ index.js
  โ”‚   โ”‚
  โ”‚   โ””โ”€โ”€ package.json
  โ”‚
  โ”œโ”€โ”€ webapp (example.com)
  โ”‚   โ”œโ”€โ”€ public
  โ”‚   โ”œโ”€โ”€ src
  โ”‚   โ”‚   โ”œโ”€โ”€ components
  โ”‚   โ”‚   โ”œโ”€โ”€ setup
  โ”‚   โ”‚   โ””โ”€โ”€ index.js
  โ”‚   โ”‚
  โ”‚   โ”œโ”€โ”€ .env
  โ”‚   โ””โ”€โ”€ package.json
  โ”‚
  โ”œโ”€โ”€ .gitignore
  โ””โ”€โ”€ README.md

๐Ÿ“˜ Guides

API

  • Adding new Module (Eg: Users):
    • Copy /api/src/models/thought.js to /api/src/models/user.js and modify the file for table name and respective fields
    • Add an entry to the models object in /api/src/models/index.js
    • Copy /api/src/schema/thoughts to /api/src/schema/users and modify type.js, resolvers.js and fields/query.js and fields/mutations.js
    • Import /api/src/schema/users/fields/query.js in /api/src/schema/query.js
    • Import /api/src/schema/users/fields/mutations.js in /api/src/schema/mutations.js

Webapp

  • Adding new Module (Eg: Users):
    • Create folder users under /webapp/src/components/
    • Create your Container and Resusable components under /webapp/src/components/users
    • Create api folder under /webapp/src/components/users
    • Add actions.js where all your Redux Action Types and Actions will reside (refer /webapp/src/components/thoughts/api/actions.js)
    • Add state.js where all your respective Reducers will recide (refer /webapp/src/components/thoughts/api/state.js)
    • Import the module state in /webapp/src/setup/store.js to make it avaliable to the app
    • Encapsulate all your User related code in /webapp/src/components/users
  • Adding new Route (Eg: /users):
    • Add a new entry to routes object in /webapp/src/setup/routes.js (eg user: { list: '/list' })
    • Edit /webapp/src/components/App.js and add the route entry

Sample GraphQL Queries

These queries are generated on client side using queryBuilder() helper defined in /webapp/src/setup/helpers.js

Query - Get List

query {
  thoughts {
    id,
    name,
    thought
  }
}
                

Response

{
  "data": {
    "thoughts": [
      {
        "id": 1,
        "name": "Arya Stark",
        "thought": "A girl has no name"
      },
      {
        "id": 2,
        "name": "Jon Snow",
        "thought": "I know nothing"
      }
    ]
  }
}
                

Query - Get by Param

query {
  thought(id: 1) {
    id,
    name,
    thought
  }
}
                

Response

{
  "data": {
    "thought": {
      "id": 1,
      "name": "Arya",
      "thought": "A girl has no name"
    }
  }
}
                

Mutation - Create

mutation {
  thoughtCreate(
    name: "Tyrion Lannister", 
    thought:"I drink and I know things"
  ) {
    id
  }
}
                

Response

{
  "data": {
    "thoughtCreate": {
      "id": 3
    }
  }
}
                

Mutation - Remove

mutation {
  thoughtRemove(id: 3) {
    id
  }
}
                

Response

{
  "data": {
    "thoughtRemove": {
      "id": null
    }
  }
}
                

๐ŸŽฉ Authors

Atul Yadav - GitHub โ€ข Twitter

Nattatorn Yucharoen - GitHub

๐Ÿ“œ License

Copyright (c) 2017 Atul Yadav http://github.com/atulmy

The MIT License (http://www.opensource.org/licenses/mit-license.php)

fullstack-graphql's People

Contributors

atulmy avatar nattatorn-dev 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.