https://github.com/mathsgod/light-graphql
https://github.com/mathsgod/light-graphql
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mathsgod/light-graphql
- Owner: mathsgod
- License: mit
- Created: 2024-09-17T07:29:40.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T10:07:42.000Z (about 1 year ago)
- Last Synced: 2025-06-06T16:04:06.363Z (about 1 year ago)
- Language: PHP
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Light GraphQL
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 `SchemaFactory` provided by the `Light\GraphQL\Server`. It allows adding namespaces for controllers.
- **Controllers**: The `Controllers` namespace is used to define resolvers for GraphQL queries.
- **GraphQL Execution**: The `Server::executeQuery` method is used to execute the GraphQL query against the schema. In the provided example, the query `$query` is executed, and the result is converted to an array using `toArray()`.
### Usage Example
```php
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
```php
use Controllers\RootController;
use GraphQL\GraphQL;
$server = new \Light\GraphQL\Server();
$server->getSchemaFactory()->addNamespace("Controllers");
$response=$server->handle($request);