Download the PHP package kuandd/graphql-relay without Composer

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

graphql-relay

基于 webonyx/graphql-php 的 relay 协议实现

动机

  1. 基于 graphql-resolve 项目,实现 relay 协议;

状态

不稳定

例子

node查询 & node接口 & global id

定义个名为order的例子查询,假设它会返回两个字段,id和sn(当前版本需要注意的是id是必填的,以后会考虑将其和实际业务做成映射关系管理起来,当然也会默认采用id这个字段,做到向后兼容)。需要注意的是,其必须引用 IsNodeQuery Trait 该特性提供对应的解析方法,为返回值增加类型标识数据来告诉 Node 接口当前要解析的类型是什么。

声明一个Order类型作为以上查询的返回类型。需要注意的是,该类型必须实现 Node 接口(GraphQL 语言中的的接口,由 NodeInterface 类型提供)。因为node查询返回的类型为Node接口。

还是需要先定义根节点查询并且将定义好的order查询和node查询作为其字段 (Field),这里的node查询为本Relay包提供的。

完成以上 Schema 结构配置和解析模拟之后,我们需要实例化Schema并使用该结构解析出对应的值:

经过以上处理将会打印结果如下:

Connection & Edge 协议

实际的业务场景里,订单一般都会有商品,我们在这里使用连接(Connection)进行关联。 再来看看订单类型:

我们在返回字段中加入了一个查询字段在类型 OrderGoodsQuery 中定义:

需要注意的是以上代码中使用了 ConnectionBuilder 来创建连接(Connection)类型,考虑到各种连接的结构大同小异,所以这里没有让开发者自行创建一个对应的链接类,而是采用构建者的方式按照"模板"来创建类型。

而模板的变量只有一个:对应的节点类型,通过参数传入。我们接下来看一下节点的代码:

节点又回到了我们最简单的类型。

最后让我们测试一下Relay-Connection协议的效果:

以上代码将输出:

Mutation input & clientMutationId 协议

创建订单并获得可预期的结果,通过clientMutationId对应请求的结果,我们需要继承 AbstractObjectType 抽象类来声明一个变更。

Relay 协议中对变更有两个主要约束:

  1. 输入参数有且只有一个input,且类型为InputObject类型;
  2. 如果参数中带有clientMutationId则,输出结果中必然有clientMutationId属性。

对于后者我没有做变通,目前只是强制添加的clientMutationId属性。

以上的输出类型代码中直接引用Order类型的字段,这种写法可以复用很多业务逻辑。

在输入参数中,目前只有一个参数userId。

我们来看看测试效果,不过这里就省略了根变更声明:

输出结果如下:

以上三种协议均已经实现,只不过该项目还处于不稳定状态,请勿部署于生产环境。

接下来要做的:

  1. connection 的 cursor 参数解析还是个问题,目前只是将callable参数传入 builder 来解决输出问题,但并没有解决参数问题。
  2. 进一步完善测试用例;

希望本轮子能节省你们的开发时间,也欢迎大家的PR。


All versions of graphql-relay with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
webonyx/graphql-php Version ^0.13
kuandd/graphql-resolve Version ^0.1
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 kuandd/graphql-relay contains the following files

Loading the files please wait ....