mathsgod/light-graphql
最新稳定版本:1.2.1
Composer 安装命令:
composer require mathsgod/light-graphql
包简介
Simple graphql server
README 文档
README
Light GraphQL is a lightweight GraphQL server implementation designed for simplicity and ease of use. This project demonstrates how to set up a basic GraphQL server using PHP.
This library is built using several dependencies, including thecodingmachine/graphqlite, which provides annotations and tools for creating GraphQL APIs in PHP. Other key dependencies include:
- league/container: A lightweight dependency injection container.
- symfony/cache: A caching library for optimizing performance.
These libraries work together to provide a robust and flexible foundation for building GraphQL servers.
Installation
composer require mathsgod/light-graphql
Key Components
-
Schema Factory: The schema is dynamically created using the
SchemaFactoryprovided by theLight\GraphQL\Server. It allows adding namespaces for controllers. -
Controllers: The
Controllersnamespace is used to define resolvers for GraphQL queries. -
GraphQL Execution: The
Server::executeQuerymethod is used to execute the GraphQL query against the schema. In the provided example, the query$queryis executed, and the result is converted to an array usingtoArray().
Usage Example
use Controllers\RootController; use GraphQL\GraphQL; require_once __DIR__ . '/vendor/autoload.php'; $server = new \Light\GraphQL\Server(); $server->getSchemaFactory()->addNamespace("Controllers"); print_R($sever->executeQuery($query)->toArray());
ServerRequestInterface handling
use Controllers\RootController; use GraphQL\GraphQL; $server = new \Light\GraphQL\Server(); $server->getSchemaFactory()->addNamespace("Controllers"); $response=$server->handle($request);
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-17