Download the PHP package fedorgrecha/php-graphql-projection without Composer
On this page you can find all versions of the php package fedorgrecha/php-graphql-projection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fedorgrecha/php-graphql-projection
More information about fedorgrecha/php-graphql-projection
Files in fedorgrecha/php-graphql-projection
Package php-graphql-projection
Short Description GraphQL projections generator for Laravel
License MIT
Informations about the package php-graphql-projection
GraphQL Projection Generator for Laravel
A PHP library for generating type-safe GraphQL queries and projections for Laravel applications. Build GraphQL requests with full IDE autocomplete, type safety, and a fluent interface.
Installation
Install via Composer:
Publish configuration:
Configuration
Configure in config/graphql-projection.php:
Note: Add
build/to.gitignore(contains generated files).
Configure Composer Autoload
Update the autoload-dev section in your root composer.json file:
Note: Use namespace and path from your configuration.
After updating composer.json, run:
Quick Start
Generate Classes
Generate type-safe classes from your GraphQL schema:
This creates:
- Query classes - Execute GraphQL operations
- Projection classes - Select fields to retrieve
- Input classes - Type-safe input data
- Type classes - Response data models
Build Your First Query
Usage Examples
Nested Objects and Arrays
Work with complex nested structures effortlessly:
File Uploads
Upload single files, multiple files, or files within nested inputs:
Field Arguments
Pass arguments to specific fields:
Union Types
Handle GraphQL union and interface types:
Pagination
Built-in support for paginated queries:
Error Handling
Two approaches for handling errors:
Working with Enums
Native PHP enum support:
Date and Time Handling
Automatic Carbon conversion:
API Reference
GraphQLTestHelpers (Trait)
Use in your test classes:
GraphQLQueryExecutor
Execute GraphQL requests: Methods:
execute(GraphQLQueryRequest $request): GraphQLResponse- Execute query, return raw responseexecuteAndExtract(GraphQLQueryRequest $request): mixed- Execute query, return typed object
GraphQLResponse
GraphQL response wrapper:
Methods:
getData(): mixed- Get response datagetErrors(): array- Get errors arrayhasErrors(): bool- Check if response has errorsgetFirstError(): ?array- Get first errorisSuccessful(): bool- Check if request was successfulgetRawResponse(): array- Get raw response array
GraphQLException
Exception thrown on GraphQL errors:
Methods:
getErrors(): array- Get GraphQL errorsgetRawResponse(): array- Get full responsegetMessage(): string- Get error message
Projection Navigation
Navigate through nested projections:
Methods:
getRoot()- Return to root projectiongetParent()- Return to parent projection
Builder Pattern
All Input and Type classes support builder pattern:
Supported GraphQL Features
Scalar Types
String,Int,Float,Boolean,ID- Custom scalars (with automatic conversion)
Complex Types
- Objects - Nested object types
- Input Objects - Input type support
- Arrays - Lists of any type
- Nullable Fields - Optional fields with null support
- Union Types - GraphQL unions with type discrimination
- Interface Types - GraphQL interfaces
Special Features
- File Uploads - GraphQL Multipart Request Spec compliant
- Pagination - Cursor and offset-based pagination
- Enums - Native PHP enum support
- Dates - Automatic Carbon/DateTime conversion
- Custom Scalars - Extensible scalar handling
Generated Code Structure
Query Class
Input Class
Type Class
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
- Lighthouse or Rebing GraphQL Laravel package
Compatible GraphQL Servers
- Lighthouse - Laravel GraphQL server
- Rebing GraphQL Laravel - Laravel GraphQL implementation
License
The MIT License (MIT).
All versions of php-graphql-projection with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
webonyx/graphql-php Version ^15