This is a simple api that you can use to store data and get it based on id or retrieve them all for rendering a graph bar.
The sample structure is in data.json in root directory and here you may see the result.
For development purposes I didn't use any framework but only two 3rd party dependencies.
I attempted to develop a micro framework with common functionality such as routing, template rendering also features like login and registration.
My goal is to simulate how a modern day framework works and only then develop the project top of the core application.
- Ubuntu - Server
- MySQL - Database
- PHP - Language
- Linux Mint 18 - OS
- PhpStorm - IDE
- Chromium - Browser
- The Yaml Component - The Yaml component loads and dumps YAML files
- GraphQL - Pure PHP realization of GraphQL protocol
These instructions will guide you to up and running the project on your local machine.
- Composer
- Apache(or Nginx)
- MySQL
In root directory you will find graph.sql. First import it to MySQL database manually.
Then update parameters in app/config/config.yml.dist and save this file as config.yml.
dataSource:
database:
host: localhost
name:
user:
password:
graphQL:
endpoint: http://localhost:8000/graphNow you can run composer install to install dependencies.
You can start the server with composer run-script serve. Below you may find route list.
| Method | Path | Info |
|---|---|---|
| GET | /graph | bar graph data |
| GET | /graphql | explorer |
| POST | /graphql | endpoint |
REST is a well-known specification but APIs based on it have some disadvantages when it comes to resolve multiple requests.
GraphQL on the other hand brings a new way that allows you to get exactly the data you’re looking for in one request.
Following examples show how queries and mutations can be ran via explorer or from command line.
This query is asking for all fields on tick object.
explorer:
{
tick(id: 1) {
id
title
name
data
borderColor
borderColorOpacity
backgroundColor
backgroundColorOpacity
borderWidth
}
}cmd:
$ curl -X POST \
-H "Content-Type: application/json" \
-d '{ "query": "{ tick(id: 1) { id title name data borderColor borderColorOpacity backgroundColor backgroundColorOpacity borderWidth } }" }' \
http://localhost/graphql
Response:
{
"data": {
"tick": {
"id": "1",
"title": "votes",
"name": "red",
"data": 12,
"borderColor": "#ff6384",
"borderColorOpacity": "1",
"backgroundColor": "#ff6384",
"backgroundColorOpacity": "0.2",
"borderWidth": 1
}
}
}addTick is asking to create a new tick object. Result will be the id.
explorer:
mutation AddTick(
$title: String!,
$name: String!,
$data: Int!,
$borderColor: String!,
$borderColorOpacity: String!,
$backgroundColor: String!,
$backgroundColorOpacity: String!,
$borderWidth: Int!
) {
addTick(
title: $title,
name: $name,
data: $data,
borderColor: $borderColor,
borderColorOpacity: $borderColorOpacity,
backgroundColor: $backgroundColor,
backgroundColorOpacity: $backgroundColorOpacity,
borderWidth: $borderWidth
)
}variables:
{
"title": "attendance",
"name": "orange",
"data": 18,
"borderColor": "#fffaa4",
"borderColorOpacity": "0.2",
"backgroundColor": "#ff9f40",
"backgroundColorOpacity": "1",
"borderWidth": 1
}cmd:
$ curl -X POST http://localhost/graphql \
-H "Content-Type: application/json" \
-d '{ "query": "mutation AddTick($title: String!, $name: String!, $data: Int!, $borderColor: String!, $borderColorOpacity: String!, $backgroundColor: String!, $backgroundColorOpacity: String!, $borderWidth: Int!) { addTick(title: $title, name: $name, data: $data, borderColor: $borderColor, borderColorOpacity: $borderColorOpacity, backgroundColor: $backgroundColor, backgroundColorOpacity: $backgroundColorOpacity, borderWidth: $borderWidth) }",
"variables": { "title": "attendance", "name": "orange", "data": 18, "borderColor": "#fffaa4", "borderColorOpacity": "0.2", "backgroundColor": "#ff9f40", "backgroundColorOpacity": "1", "borderWidth": 1 } }'
Response:
{
"data": {
"addTick": 12
}
}- How to Make a PHP Template Engine
- Slim Session
- An Introduction to Services
- Integrating the Data Mappers
- Options FollowSymLinks Giving Me 500 Internal Server Error
- Mage2.pro Topic 1392
- Bootstrap Navbar Active State Not Working
- password_verify Returns False for Correct Password
- Convert Hex Color to RGB Using PHP
- Youshido GraphQL
- jQuery Table Sorter Demo
- Hex to RGBA Converter

