Download the PHP package andyharis/yii2apigql without Composer
On this page you can find all versions of the php package andyharis/yii2apigql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2apigql
andyharis/yii2-apigql
yii2-apigql provides methods to work with database on CRUD operations
Usage
API docs
For example we have 3 table/models: Users, Messages, Post.
Users
-> hasManyPost
Post
-> hasManyMessages
We want to access clients with all messages including post:
Make request and get all data with the same format you provided.
GET /clients?select={"username": "","avatarUrl": "","post": {"postName": "","messages": {"textMessage": "","dateAdded": ""}}}
- Access main model and nested relations data with one query.
- Sort by nested relations:
/clients?select={...}&sort=post.postName
- sort bypost.postName ASC
/clients?select={...}&sort=!post.messages.dateAdded
- sort bypost.messaged.dateAdded DESC
- Filter data with nested conditions:
/clients?select={"username":"=Andyhar"}
- whereusername equals Andyhar
/clients?select={"post":{"messages":{"textMessage":"~Rocks"}}}
- wherepost.messages.textMessage like Rocks
/clients?select={"post":{"likes":">35"}}
- wherepost.likes > 35
Installation
The preferred way to install this extension is through composer. Either run
Getting started
After installation you should enable this module extension in your config file:
- Open your
frontend/config/main.php
- Add module
gql
tobootstrap
section
Then you need to initialize component itself.
Just add new component gql
to list of your components:
Creating file models.php
As you can see we require 'models.php'
to let component know which models to use.
So you probably want create a separate file to store you models for this case.
Where:
clients
- indicates name for your model\frontend\models\Clients::className()
- indicates what model should use to fetch and update data
Almost there
Another important thing is to extend all your models with Yii2ApigqlRecord
component.
That's it. Now you can work with yii2apigql
.
For more info please visit Wiki for API documentation.