定制 biohzrdmx/liteql-php 二次开发

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

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

biohzrdmx/liteql-php

Composer 安装命令:

composer require biohzrdmx/liteql-php

包简介

Barebones GraphQL client library

README 文档

README

Barebones GraphQL client library.

With LiteQL you will be able to run GraphQL queries easily, without requiring to create complicate schemas or generating code. You just run a query and get the result or receive an exception.

Also, you get to choose the PSR-17/18 implementation used, so you get a lightweight and flexible alternative.

Basic usage

First require biohzrdmx/liteql-php with Composer.

Next you need to create a LiteQL\Client instance, to do so you must pass two parameters to the constructor:

  • $http_client - An instance of an implementation of ClientInterface (PSR-18)
  • $request_factory - An instance of an implementation of RequestFactoryInterface (PSR-17)

You are free to choose which implementation to use, just pass both instances to the create method of LiteQL\Client for easy chaining.

Then use the other methods such as setUri, setHeader to configure the client, leveraging the fluent interface.

Now it's time to build the Query itself, to do so you can create it from a string (with the fromString method) or from a .graphql file (using the fromFile method).

Please do note that at this point the fluent interface returns a Query instance, so you may add variables with the setVariable method if you want.

Finally, call the execute method and you should get a Result object.

The full flow looks like the following example:

use AwesomeSauce\HttpCLient;
use AwesomeSauce\RequestFactory;

use LiteQL\Client; 

$http_client = new HttpClient();
$request_factory = new RequestFactory();
$result = Client::create($http_client, $request_factory)
    ->setUri('https://dummy-pokemon-graphql.local')
    ->fromString('query GetPokemon($name: String) {pokemon(name: $name) {id number name } }')
    ->setVariable('name', 'Pikachu')
    ->execute();

To load the query from a file:

$result = Client::create($http_client, $request_factory)
    ->setUri('https://dummy-pokemon-graphql.local')
    ->fromFile('/path/to/queries/directory/getPokemon.graphql')
    ->setVariable('name', 'Pikachu')
    ->execute();

Either way you will get a Result object or a ClientException will be thrown (if for example you need authentication, or you hit a request limit, etc.).

Result object

The Result object has the following methods:

  • getResponse - Get the raw ResponseInterface implementation
  • getStatusCode - Get the status code (anything <200 or >299 will generate an exception)
  • getData - Get the parsed data from the response (if the Content-Type header is application/json, otherwise an exception will be thrown)

Now you can do whatever you want with the returned data, cache it, parse it, display it, etc.

That's it, you need no introspection or schemas or anything else to query a GraphQL server, just prepare your queries and pass some variables.

Licensing

This software is released under the MIT license.

Credits

Lead coder: biohzrdmx <github.com/biohzrdmx>

biohzrdmx/liteql-php 适用场景与选型建议

biohzrdmx/liteql-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-30