From the official website:
A query language for your API GraphQL is a query language for APIs
and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
Tools( libs) that I used in this repo:
- Knex.js
- "Knex.js is a "batteries included" SQL query builder for Postgres, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use. It features both traditional node style callbacks as well as a promise interface for cleaner async flow control, a stream interface, full featured query and schema builders, transaction support (with savepoints), connection pooling and standardized responses between different query clients and dialects."
- ExpressJS 2. "Fast, unopinionated, minimalist web framework for Node.js"
- graphiql: 3. Graphic query editor
So, what this is example is all about?
In this repo we simulate a company database with customers and orders tables, and a web nodejs project which exposes a GraphQL endpoint.
Let's jump to it
- Clone this repo
git clone https://github.com/joelgarciajr84/grapqhl-nodejs-mysql
- run npm install
npm i
- cd to src folder and create your .env file with the settings:
DB_NAME DB_HOST DB_USER DB_PASS
- run
knex migrate:latest --knexfile ./src/knexfile.js
- run project with
node server.js
- open the browser in
[http://localhost:4000/api]
(http://localhost:4000/api)
This is it!