phonetworks/pho-lib-graphql-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phonetworks/pho-lib-graphql-parser

Composer 安装命令:

composer require phonetworks/pho-lib-graphql-parser

包简介

A general purpose GraphQL parser library in PHP

README 文档

README

A general purpose GraphQL schema parser library in PHP. This library does not parse GraphQL queries or responses.

Installation

The recommended way to install pho-lib-graphql-parser is through composer. It's as simple as:

composer require phonetworks/pho-lib-graphql-parser

Usage

Suppose you have the following GraphQL schema file as BasicSchema.graphql:

type Basic implements Something {
  id: ID!,
  context: String!
  user: User @the_directive(the_argument: "TheValue")
}

Then, you can parse it via:

$parsed = new Pho\Lib\GraphQL\Parser\Parse("BasicSchema.graphql");
foreach($parsed as $entity) {
  $entity_name = $entity->name(); // Basic
  $implementations = $entity->implementations(); // an array with a single element
  $implementation_name = $entity->implementations(0)->name(); // Something
  $directives = $entity->directives(); // no root level directive. But we would have one if it was type Basic @is_a { ...
  $fields = $entity->fields(); // we have three; id, context and user.
  $field_1["name"] = $entity->field(0)->name(); // id
  $field_1["type"] = $entity->field(0)->type(); // ID
  $field_1["nullable"] = $entity->field(0)->nullable(); // false (due to !)
  $field_3["directives"][0] = $entity->field(0)->directive(0)->name(); // the_directive
  $field_3["directives"][0]["arguments"][0]["name"] = $entity->field(0)->directive(0)->name(); // the_argument
  $field_3["directives"][0]["arguments"][0]["value"] = $entity->field(0)->directive(0)->value(); // TheValue 
}

Please note, for argument values, we currently support String only.

A note on multiple inheritance

As of version 3.0, this is a pure PHP library. However, you may want to enable C extensions in case you need "multiple inheritance" which is not currently supported in the pure PHP mode.

For multiple inheritance, the following dependencies must be met before installing pho-lib-graphql-parser. Please note, the patches shown must be applied since schema support is still experimental.

  1. The LibGraphQLParser library by Facebook. Make sure the experimental schema support is enabled with this patch.
  2. The graphql-parser-php PHP extension. Make sure the experimental schema support is enabled with this patch.

To enable it in the library side, you need to set an environment variable where this program is run as follows:

LIBGRAPHQL_ON=true

Once you do that, you may test multiple inheritance by commenting out "return" statements in the tests/SchemaWithMultipleInheritanceTest.php file.

License

Released under the terms of the permissive MIT license.

统计信息

  • 总下载量: 167
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固