Download the PHP package plato-solutions/yii2-graphql without Composer

On this page you can find all versions of the php package plato-solutions/yii2-graphql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-graphql

yii2-graphql

Using GraphQL PHP server implementation. A fork of yii2-graphql which extends graphql-php to apply to Yii2.

Guide (For Yii Basic Template)

Same as for Yii Advanced Template, but

Guide (For Yii Advanced Template)

Install

Using composer

Enable Yii JsonParser

To enable parsing for JSON requests in backend/config/main.php

Create a GraphQLModule

  1. Create a folder modules in your base path (ie backend)

  2. Create a graphql folder in the modules folder. Thus backend/modules/graphql

  3. Create a GraphqlModule.php file in there with the following content: backend/modules/graphql/GraphqlModule.php

    1. In backend/config/main.php find the modules config and add to it so it looks like this:

Create a Controller

  1. In your modules/graphql folder create a controllers folder.
  2. Create a DefaultController.php file in there with the following content:

Create GraphQL Types

For a model in folder backend/models like the example below,

where Person is another Model with it's own attributes just like the Country

  1. Create a folder in your module modules/graphql/ and name it types.
  2. Create a CountryType.php (name it after your model class, suffix with Type) the following content

Do the above for all the models in backend\models.

For a full list of the types available under Type, see Scalar Types below.

Create GraphQL Queries for Models

  1. Create a folder in your module modules/graphql/ and name it queries.
  2. Create a CountryQuery.php (name it after your model class, suffix with Query) the following content

Do the above for all the models in backend\models you want to have queries for.

Set Up Schema

  1. In backend/modules/graphql/ create a php file schema.php with the content:

  2. In backend/config/main.php in the part about modules add a path to the schema.php as follows (make sure the directory path to schema is right).

Docs

Type

The type system is the core of GraphQL, which is embodied in GraphQLType. By deconstructing the GraphQL protocol and using the graph-php library to achieve fine-grained control of all elements, it is convenient to extend the class according to its own needs

Scalar Types

The GraphQL specification describes several built-in scalar types. In graphql-php they are exposed as static methods of the class GraphQL\Type\Definition\Type:

Data Type GraphQL Type
id Type::id()
int Type::int()
string Type::string()
boolean Type::boolean()
float Type::float()

The main elements of GraphQLType

The following elements can be declared in the $attributes property of the class, or as a method, unless stated otherwise. This also applies to all elements after this.

Element Type Description
name string Required Each type needs to be named, with unique names preferred to resolve potential conflicts. The property needs to be defined in the $attributes property.
description string A description of the type and its use. The property needs to be defined in the $attributes property.
fields array Required The included field content is represented by the fields () method.
resolveField callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info) For the interpretation of a field. For example: the fields definition of the user property, the corresponding method is resolveUserField(), and $value is the passed type instance defined by type.

Query

GraphQLQuery and GraphQLMutation inherit GraphQLField. The element structure is consistent, and if you would like a reusable Field, you can inherit it. Each query of Graphql needs to correspond to a GraphQLQuery object. ModelQuery inherits from GraphQLQuery.

The main elements of GraphQLField

Element Type Description
type ObjectType For the corresponding query type. The single type is specified by GraphQL::type, and a list by Type::listOf(GraphQL::type).
args array The available query parameters, each of which is defined by Field.
resolve callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info) $value is the root data, $args is the query parameters, $context is the yii\web\Application object, and $info resolves the object for the query. The root object is handled in this method.

Mutation

Definition is similar to GraphQLQuery, please refer to the above.

Simplified Field Definition

Simplifies the declarations of Field, removing the need to defined as an array with the type key.

Standard Definition

Simplified Definition

Input validation

Validation rules are supported. In addition to graphql based validation, you can also use Yii Model validation, which is currently used for the validation of input parameters. The rules method is added directly to the mutation definition.

Authorization verification

Since graphql queries can be combined, such as when a query merges two query, and the two query have different authorization constraints, custom authentication is required. I refer to this query as "graphql actions"; when all graphql actions conditions are configured, it passes the authorization check.

Authenticate

In the behavior method of controller, the authorization method is set as follows

If you want to support IntrospectionQuery authorization, the corresponding graphql action is __schema

Authorization

If the user has passed authentication, you may want to check the access for the resource. You can use GraphqlAction's checkAccess method in the controller. It will check all graphql actions.


All versions of yii2-graphql with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
yiisoft/yii2 Version ^2.0.
webonyx/graphql-php Version ^14.6.2
ecodev/graphql-upload Version ^6.1.0
zendframework/zend-diactoros Version ^2.1
phpunit/php-code-coverage Version 9.2.x-dev
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package plato-solutions/yii2-graphql contains the following files

Loading the files please wait ....