Download the PHP package moxuandi/yii2-graphql without Composer

On this page you can find all versions of the php package moxuandi/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

yii-graphql

使用 Facebook GraphQL 的PHP服务端实现. 扩展 graphql-php 以适用于 YII2.

Latest Stable Version Build Status Total Downloads


Englist document


yii-graphql特点

安装

使用 composer 安装:

Type

类型系统是GraphQL的核心,体现在GraphQLType中,通过解构graphql协议,并利用graph-php库达到细粒度的对所有元素的控制,方便根据自身需要进行类扩展.

GraphQLType的主要元素, 注意元素并不对应到属性或方法中(下同)

元素 类型 说明
name string Required 每一个类型都需要为其命名,如果能唯一是比较安全,但并不强制,该属性需要定义于attribute中
fields array Required 包含的字段内容,以fields()方法体现.
resolveField callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info) 对于字段的解释,比如fields定义user属性,则对应的解释方法为resolveUserField() ,$value指定为type定义的类型实例

Query

GraphQLQuery,GraphQLMutation继承了GraphQLField,元素结构是一致的,想做对于一些复用性的Field,可以继承它. Graphql的每次查询都需要对应到一个GraphQLQuery对象

GraphQLField的主要元素

元素 类型 说明
type ObjectType 对应的查询类型,单一类型用GraphQL::type指定,列表用Type::listOf(GraphQL::type)
args array 查询需要使用的参数,其中每个参数按照Field定义
resolve callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info),$value为root数据,$args即查询参数,$context上下文,为Yii的yii\web\Application对象,$info为查询解析对象,一般在这个方法中处理根对象

Mutation

与GraphQLQuery是非常相像,参考说明.

简化处理

简化了Field的声明,字段可直接使用type

在YII使用

本组件采用trait的方式在Component组件中被引入,组件宿主建议的方式是Module

Yii config file:

采用的是actions的方法进行集成

在采用动态解析的情况下,如果不想定义types时,schema的写法有讲究.可采用Type::class,避免采用Key方式,也方便直接通过IDE导航到对应的类下

输入验证

针对mutation的数据提交,提供了验证支持. 除了graphql基于的验证外,还可以使用yii的验证,目前为针对输入参数验证.直接在mutation定义中增加rules方法, 与Yii Model的使用方式是一致的.

授权验证

由于graphql查询是可以采用组合方式,如一次查询合并了两个query,而这两个query具有不同的授权约束,因此在graph中需要采用自定义的验证方式。 我把这多次查询查询称为graphql actions;当所有的graphql actions条件都满足配置时,才通过授权检查。

授权

在controller的行为方法中设置采用的授权方法,例子如下,

如果要支持IntrospectionQueryr的授权,相应的graphql action为"__schema"

Demo

创建基于graphql协议的查询

每次查询对应一个GraphQLQuery文件,

根据查询协议定义类型文件

查询实例

深入了解

有必要了解一些graphql-php的相关知识,这部分git上的文档相对还少些,需要对源码的阅读.下面列出重点

DocumentNode (语法解构)

Future


All versions of yii2-graphql with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
yiisoft/yii2 Version ~2.0.35
webonyx/graphql-php Version ^14.3
ecodev/graphql-upload Version ^6.0.0
laminas/laminas-diactoros Version ^2.4.0
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 moxuandi/yii2-graphql contains the following files

Loading the files please wait ....