定制 axtiva/flexible-graphql-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

axtiva/flexible-graphql-php

Composer 安装命令:

composer require axtiva/flexible-graphql-php

包简介

Schema SDL first lib for generate php code from graphql sdl to TypeRegistry with webonyx/graphql-php

README 文档

README

Schema first lib for generate php code from graphql sdl to TypeRegistry whom support webonyx/graphql-php with simple integrate to any controller.

TL;DR

Can easy to integrate graphql to any project, all you need is controller. Fast start with example

Features:

Setup

Composer install:

composer require axtiva/flexible-graphql-php

Examples:

Demo

Up Dev server for test http Graphql requests:

php -S localhost:8080 example/start_graphql_server.php

Change schema and run example commands

Update TypeRegistry and model classes from schema and resolvers map:

php example/generate_code.php

If you need to make field resolver, then remove AutoGenerationInterface from model CodedCurrencyType

Example:

- final class CodedCurrencyType implements AutoGenerationInterface, NodeInterface, CurrencyInterface
+ final class CodedCurrencyType implements NodeInterface, CurrencyInterface
{
    public string $id;
-   public int $code;
}

and run php example/generate_code.php, after this you will find in example/GraphQL/Resolver/CodedCurrency/CodeResolver.php. this is your field resolver, define him in your psr container like PsrContainerExample in example/start_graphql_server.php:

$container = new PsrContainerExample([
    \Axtiva\FlexibleGraphql\Example\GraphQL\Resolver\Query\AccountResolver::class =>
        new \Axtiva\FlexibleGraphql\Example\GraphQL\Resolver\Query\AccountResolver,
+   \Axtiva\FlexibleGraphql\Example\GraphQL\Resolver\CodedCurrency\CodeResolver::class =>
+       new \Axtiva\FlexibleGraphql\Example\GraphQL\Resolver\CodedCurrency\CodeResolver,
]);

Run demo app php -S localhost:8080 example/start_graphql_server.php and try request CodedCurrency.code field in query

Amphp v3 Async Execution

AmpFutureAdapter bridges Amphp v3 Future objects with the webonyx/graphql-php promise system, enabling fully non-blocking GraphQL execution.

Setup

use Axtiva\FlexibleGraphql\Executor\AmpFutureAdapter;
use GraphQL\Server\ServerConfig;
use GraphQL\Server\StandardServer;
use Amp\Future;

$config = ServerConfig::create()
    // ... schema, root value, etc.
    ->setPromiseAdapter(new AmpFutureAdapter());

$server = new StandardServer($config);
$promise = $server->executePsrRequest($psrRequest);

$response = null;
if ($promise->adoptedPromise instanceof Future) {
    $response = $promise->adoptedPromise->await()->toArray();
}

return new JsonResponse($response);

Notes

  • Every field resolver that returns an Amphp Future is automatically wrapped via Amp\async() by the generated TypeRegistry when you use the TypeRegistryGeneratorBuilderAmphp builder.
  • amphp/amp is a suggested dependency; add it explicitly when async execution is needed:
composer require amphp/amp:^3

Tests

Run tests

php vendor/bin/phpunit 

PHPStan

Run PHPStan

php vendor/bin/phpstan analyse -c phpstan.neon

axtiva/flexible-graphql-php 适用场景与选型建议

axtiva/flexible-graphql-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.21k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2021 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 axtiva/flexible-graphql-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 axtiva/flexible-graphql-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 axtiva/flexible-graphql-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 22
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-16