Code Monkey home page Code Monkey logo

gql2sql's Introduction

GQL2SQL API Service

This simple node app serves as example of a GraphQL API service in front of a legacy SQL database. It shows usage of Sequelize to interact with a MSSQL database (never need to write a single SQL command), and some tooling like:

  • Babel (full ES6, incl. imports for example)
  • Logging with Winston (console and Loggly)
  • Testing with Mocha and Chai
  • Linting (ESLint)

Installation / Development

Prerequisites:

  • Git
  • Node.js
  • Babel
  • MSSQL (with an Items table as described in models/items/ItemModel.js)

Of course you can also implement your own Model by using the 'modules/items' folder as a guide. Once you have your own module folder, you will need to add the appropriate GraphQL resolve functions to the Query.js and Mutation.js files as well. Remember, this repo is meant as a guiding example, putting together a bunch of tools that you may want to make use of.

Installation:

  1. Clone this repo
  2. Install dependencies: npm install
  3. Run the service: npm start

Feel free to submit pull requests for enhancements!

Testing:

  1. npm test will run any tests in the test folder

Schema / Models

Currently only a generic model of "Items" has been implemented. It can serve as a guide to add more models to expose (both in Sequelize and GraphQL).

screenshot

GraphQL and Sequelize

GraphQL is used as an efficient abstraction layer to read from or write to the MSSQL database, based on pre-defined data schemas. Unlike with REST APIs, with GraphQL you retrieve only what you query for, parameterized and fast. The response is always valid JSON, which makes working with the returned data very easy in most languages.

Behind the scenes, the SQL endpoints are managed by the Sequelize ORM, in order to abstract away from manually constructed SQL statements. Sequelize takes care of security, data type validations and transaction management when accessing the SQL back-end.

Btw, using the combination of GraphQL with a SQL ORM, the API Service is also secure from SQL Injection, which is neat.

TODOs

Backlog In Progress Done
Connect with MSSQL
Add GraphiQL IDE
Use Sequalize ORM
Central Configuration
Items Schema
Service Authentication
Logging (Winston -> Loggly)
Test examples
Process Runner/Cluster
Change to Apollo Tools

...

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.