### Setup and Run PHP Server (Bash) Source: https://github.com/thecodingmachine/graphqlite/blob/master/examples/no-framework/README.md Executes Composer to install project dependencies and then starts the PHP built-in web server, making the application accessible at http://127.0.0.1:8080. ```bash composer install php -S 127.0.0.1:8080 ``` -------------------------------- ### Install GraphQLite Bundle (Symfony Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications using Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Install GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/other-frameworks.mdx Installs the GraphQLite library using the Composer dependency manager. This command should be run in the project's root directory. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Installing GraphQLite with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/other-frameworks.mdx This command installs the GraphQLite library into your PHP project using Composer. It fetches the necessary dependencies to integrate GraphQLite. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-3.0/other_frameworks.mdx Use Composer, the PHP dependency manager, to add the GraphQLite library to your project. This command downloads and installs the package and its dependencies. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Installing GraphQLite with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/other-frameworks.mdx Installs the GraphQLite library using the Composer package manager. This command adds the library as a dependency to your project. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite Universal Service Provider Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/universal-service-providers.md Installs the `thecodingmachine/graphqlite-universal-service-provider` package using Composer, which provides integration with `container-interop/service-provider` compatible frameworks. ```console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Minimal GraphQLite Setup (No Framework) - PHP Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/other-frameworks.mdx Demonstrates a basic, framework-agnostic setup for GraphQLite. It initializes the schema factory, creates a schema, handles raw HTTP input, executes a GraphQL query using `webonyx/graphql-php`, and outputs the JSON result. ```php addNamespace('App'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Installing GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Command to add the GraphQLite library as a dependency using Composer. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications utilizing Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Minimal GraphQLite Example (No Framework) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/other-frameworks.mdx Provides a complete, minimal working example of setting up and using GraphQLite without a specific framework. It demonstrates creating the schema, handling raw HTTP input, executing a query with the required Context, and outputting the result as JSON. Requires a PSR-16 cache and PSR-11 container. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Defining Project Dependencies (composer.json) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/other-frameworks.mdx Defines the project dependencies required for this example setup, including GraphQLite, Laminas components for HTTP handling, Mouf/Picotainer for the container, and Symfony/Cache for caching. It also sets up the PSR-4 autoloading for the `App` namespace. ```json { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^4", "laminas/laminas-diactoros": "^2", "laminas/laminas-stratigility": "^3", "laminas/laminas-httphandlerrunner": "^2", "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Installing GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.1/other_frameworks.mdx Command to add the GraphQLite library as a dependency to your project using Composer. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications utilizing Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Installing GraphQLite Laravel Package (Console) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/laravel-package.md Command to install the GraphQLite Laravel package using Composer. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Install GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/other-frameworks.mdx Use Composer to add the thecodingmachine/graphqlite library to your project dependencies. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite Laravel Package (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/laravel-package.md Command to install the GraphQLite Laravel package using Composer. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Composer Dependencies for GraphQLite PSR-7 Setup (JSON) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-3.0/other_frameworks.mdx Defines the required PHP packages for the advanced GraphQLite example, including GraphQLite itself, the PSR-7 GraphQL middleware, PSR-7 implementations (zend-diactoros), the PSR-15 middleware pipe (zend-stratigility), a PSR-11 container (picotainer), and a PSR-16 cache (symfony/cache). ```json { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^3", "phps-cans/psr7-middleware-graphql": "^0.2", "middlewares/payload": "^2.1", "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer to add the GraphQL Playground web UI to a Laravel project. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Install GraphQLite Universal Service Provider (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/universal-service-providers.md Installs the required GraphQLite universal service provider package using Composer. ```console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Install Laravel GraphQL Playground (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/laravel-package.md Command to install the Laravel GraphQL Playground package using Composer. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Install GraphQLite Bundle (Non-Flex Symfony) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications not using Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Minimal GraphQLite Example (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Provides a complete, minimal example demonstrating how to initialize GraphQLite, create a schema, handle an incoming HTTP request, execute a GraphQL query, and return the JSON response, suitable for integration without a full framework. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Install GraphQLite Bundle with Composer (No Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications not utilizing Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Install GraphQLite Universal Service Provider via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-3.0/universal_service_providers.md Installs the `thecodingmachine/graphqlite-universal-service-provider` package using Composer, adding it as a dependency to your project. ```Console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Minimal GraphQLite Example (No Framework) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/other-frameworks.mdx Provides a complete, minimal example demonstrating how to set up GraphQLite, create a schema, execute a GraphQL query received via HTTP POST, and return the JSON result, without relying on a specific framework. It includes handling input, executing the query, and sending the response. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Minimal Standalone GraphQLite Example Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/other-frameworks.mdx A complete, basic PHP script showing how to set up GraphQLite, create a schema, read a GraphQL query from standard input, execute it using Webonyx, and output the JSON result. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/laravel-package.md Installs the `xkojimedia/laravel-altair-graphql` package using Composer to add the Altair GraphQL Client web UI to a Laravel project. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Install GraphQLite with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/other-frameworks.mdx Use Composer to add the GraphQLite library to your project dependencies. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Installing GraphQLite via Composer (Console) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/other_frameworks.mdx Command to add the GraphQLite library as a dependency to your project using Composer. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Install GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/other-frameworks.mdx Installs the GraphQLite library into your PHP project using the Composer dependency manager. This command adds the necessary package to your project's dependencies. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Installing GraphQL Playground (Console) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-3.0/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer to provide a web-based UI for querying the GraphQL endpoint. This is an optional dependency for development. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Installing GraphQLite via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/other-frameworks.mdx Command to add the GraphQLite library as a dependency to your PHP project using the Composer package manager. ```console $ composer require thecodingmachine/graphqlite ``` -------------------------------- ### Setup PSR-15 Request Handler (index.php) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Initializes the application entry point using Laminas Diactoros for requests/responses and Zend Stratigility/HttpHandlerRunner to process requests via a middleware pipe. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer. This package provides a web-based UI for interacting with your GraphQL endpoint, typically available at `/graphql-playground`. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Installing GraphQLite Laravel Package (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/laravel-package.md Installs the `thecodingmachine/graphqlite-laravel` package using Composer. This is the first step to integrate GraphQLite into a Laravel project. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer to add the GraphQL Playground web UI for querying the GraphQL endpoint. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Minimal GraphQLite Example Script (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/other-frameworks.mdx Provides a complete, self-contained PHP script demonstrating how to set up GraphQLite, create a schema, read a GraphQL query from the HTTP request body, execute it using the webonyx/graphql-php library with the required GraphQLite context, and output the result as JSON. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/laravel-package.md Use Composer to install the xkojimedia/laravel-altair-graphql package, offering an alternative web-based GraphQL client for your Laravel application. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Install GraphQLite Bundle via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/symfony-bundle.md Installs the GraphQLite bundle using Composer. This command is used for both Symfony Flex and non-Flex applications. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/laravel-package.md Installs the mll-lab/laravel-graphql-playground package using Composer to add the GraphQL Playground web UI for querying the GraphQL endpoint. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/laravel-package.md Installs the xkojimedia/laravel-altair-graphql package using Composer to add the Altair GraphQL Client web UI for querying the GraphQL endpoint. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/laravel-package.md Installs the `xkojimedia/laravel-altair-graphql` package using Composer to add the Altair GraphQL Client web UI for querying the GraphQL endpoint. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Installing Laravel GraphQL Playground via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.1/laravel-package.md Installs the Laravel GraphQL Playground package using Composer, providing a web-based IDE for interacting with the GraphQL endpoint. ```console composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Minimal GraphQLite Integration Example (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/other_frameworks.mdx A complete example demonstrating how to initialize the SchemaFactory, create the schema, handle incoming HTTP requests, execute a GraphQL query with the required context, and output the JSON result. Requires PSR-11 container and PSR-16 cache. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Minimal GraphQLite Example (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/other-frameworks.mdx Provides a complete, minimal example of using GraphQLite without a framework. It shows schema creation, reading the GraphQL query from the request body, executing the query using webonyx/graphql-php, and outputting the JSON result. ```php addControllerNamespace('App\\Controllers') ->addTypeNamespace('App'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Symfony Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer. This command is used for applications managed with Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/laravel-package.md Installs the `xkojimedia/laravel-altair-graphql` package using Composer. This package integrates the Altair GraphQL Client, another web-based UI for querying your GraphQL endpoint. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Zend Stratigility Server Setup (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/other-frameworks.mdx Initializes the Zend Stratigility RequestHandlerRunner, setting up the PSR-15 server entry point. It configures the request factory, error handling, and uses a MiddlewarePipe retrieved from the PSR-11 container to process incoming requests. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Install GraphQLite Universal Service Provider Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/universal-service-providers.md Installs the GraphQLite universal service provider package using Composer, which is required for integration with container-interop/service-provider compatible frameworks. ```console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Install GraphQLite Universal Service Provider via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/universal-service-providers.md Use Composer to add the GraphQLite universal service provider package to your project dependencies. This command downloads and installs the necessary files. ```console composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Initialize Container and Get GraphQLite Schema/Middleware (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/universal-service-providers.md Demonstrates setting up a Simplex container, registering necessary service providers (cache, annotations, GraphQLite), configuring namespaces for types and controllers, and retrieving the GraphQL Schema or the PSR-15 middleware builder from the container. ```php set('graphqlite.namespace.types', ['App\\Types']); $container->set('graphqlite.namespace.controllers', ['App\\Controllers']); $schema = $container->get(Schema::class); // or if you want the PSR-15 middleware: $middleware = $container->get(Psr15GraphQLMiddlewareBuilder::class); ``` -------------------------------- ### Building GraphQLite PSR-15 Middleware (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Demonstrates how to instantiate the Psr15GraphQLMiddlewareBuilder using a GraphQL schema and create the middleware instance. It also shows an example of piping the middleware into a PSR-15 compatible middleware pipe like Zend-Expressive. ```php // $schema is an instance of the GraphQL schema returned by SchemaFactory::createSchema (see previous chapter) $builder = new Psr15GraphQLMiddlewareBuilder($schema); $middleware = $builder->createMiddleware(); // You can now inject your middleware in your favorite PSR-15 compatible framework. // For instance: $zendMiddlewarePipe->pipe($middleware); ``` -------------------------------- ### Setting up Application Entry Point (index.php) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.1/other_frameworks.mdx This index.php file serves as the application's entry point. It includes the autoloader, retrieves the container, sets up the server request factory, defines an error response generator, and initializes and runs the RequestHandlerRunner with the MiddlewarePipe from the container. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Create Example GraphQL Controller Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Defines a simple PHP class with a method annotated as a GraphQL query using GraphQLite annotations (PHP 8 attribute or PHP 7 docblock). ```php namespace App\Controllers; use TheCodingMachine\GraphQLite\Annotations\Query; class MyController { #[Query] public function hello(string $name): string { return 'Hello '.$name; } } ``` ```php namespace App\Controllers; use TheCodingMachine\GraphQLite\Annotations\Query; class MyController { /** * @Query */ public function hello(string $name): string { return 'Hello '.$name; } } ``` -------------------------------- ### Install GraphQLite Bundle (Symfony Flex) - Console Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-7.0.0/symfony-bundle.md Installs the GraphQLite bundle using Composer for Symfony applications utilizing Symfony Flex. This command adds the bundle as a project dependency. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Composer Dependencies for GraphQLite Setup (JSON) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/other-frameworks.mdx Defines the project dependencies required for the GraphQLite setup using Zend Stratigility, Picotainer, and Symfony Cache, including autoloading configuration for the application's source files. ```json { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^4", "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Install GraphQLite Universal Service Provider with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/universal_service_providers.md Installs the `thecodingmachine/graphqlite-universal-service-provider` package using Composer, which is required for integrating GraphQLite with `container-interop/service-provider` compatible frameworks. ```console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Composer Dependencies for GraphQLite Example (JSON) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.0/other-frameworks.mdx Defines the required dependencies for the example project using Composer, including GraphQLite, Zend Stratigility, Zend Diactoros, Zend HttpHandlerRunner, and Symfony Cache. ```json { "autoload": { "psr-4": { "App\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^4", "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Application Entry Point (index.php) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/other-frameworks.mdx Sets up the main application entry point using Laminas components. It includes the autoloader, loads the container configuration, defines request and error handling factories, and initializes and runs the RequestHandlerRunner with the MiddlewarePipe from the container. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Install GraphQLite Universal Service Provider Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/universal-service-providers.md Use Composer to add the thecodingmachine/graphqlite-universal-service-provider package to your project dependencies. ```console composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Installing GraphQLite Universal Service Provider with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/universal-service-providers.md Installs the `thecodingmachine/graphqlite-universal-service-provider` package using Composer. This package provides the necessary service provider for integration with `container-interop/service-provider` compatible frameworks. ```console $ composer require thecodingmachine/graphqlite-universal-service-provider ``` -------------------------------- ### Setting up Laminas Stratigility Application Runner (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/other-frameworks.mdx This `index.php` script initializes and runs a Laminas Stratigility application. It sets up a `RequestHandlerRunner` with a `MiddlewarePipe` obtained from the container, configures request creation from globals, and defines a basic error response generator. It requires the autoloader and the container configuration. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer, adding the GraphQL Playground web UI to a Laravel project for querying the GraphQL endpoint. This tool provides an interactive interface for testing GraphQL queries and mutations. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/laravel-package.md Installs the `xkojimedia/laravel-altair-graphql` package using Composer. This package integrates the Altair GraphQL Client web UI into your Laravel application for interacting with your GraphQL endpoint. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Installing GraphQLite Laravel Package (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/laravel-package.md Command to add the `thecodingmachine/graphqlite-laravel` package as a dependency to your project using Composer. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Setting up Request Handler Runner (index.php) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/other_frameworks.mdx Initializes the application entry point using Zend/Laminas Diactoros and Stratigility. It sets up a `RequestHandlerRunner` with a `MiddlewarePipe` obtained from the container, an emitter, a request factory, and an error response generator. ```php get(MiddlewarePipe::class), new SapiStreamEmitter(), $serverRequestFactory, $errorResponseGenerator ); $runner->run(); ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Symfony Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.1/symfony-bundle.md Installs the GraphQLite bundle using Composer for Symfony applications utilizing Symfony Flex. This command adds the bundle as a project dependency. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Minimal GraphQL Request Handling Example (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-3.0/other_frameworks.mdx A basic example demonstrating how to handle an incoming GraphQL HTTP request. It shows creating the schema, reading the raw JSON input, executing the query using the Webonyx library, and outputting the JSON result with the correct content type header. ```php addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null; $result = GraphQL::executeQuery($schema, $query, null, null, $variableValues); $output = $result->toArray(); header('Content-Type: application/json'); echo json_encode($output); ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.3/laravel-package.md Installs the `mll-lab/laravel-graphql-playground` package using Composer. This package provides the GraphQL Playground web UI for querying your GraphQL endpoint within your Laravel application. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Install GraphQLite Laravel Package via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/laravel-package.md Command to install the GraphQLite package and its dependencies into a Laravel project using Composer. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Install GraphQLite Laravel Package via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/laravel-package.md Installs the GraphQLite Laravel package using Composer, adding it as a dependency to your project. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Configure PSR-11 Container (Initial) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Sets up the Picotainer instance, defining services like the MiddlewarePipe, GraphQL middleware, Cache interface, and the GraphQLite SchemaFactory. ```php function(ContainerInterface $container) { $pipe = new MiddlewarePipe(); $pipe->pipe($container->get(WebonyxGraphqlMiddleware::class)); return $pipe; }, // The WebonyxGraphqlMiddleware is a PSR-15 compatible // middleware that exposes Webonyx schemas. WebonyxGraphqlMiddleware::class => function(ContainerInterface $container) { $builder = new Psr15GraphQLMiddlewareBuilder($container->get(Schema::class)); return $builder->createMiddleware(); }, CacheInterface::class => function() { return new ApcuCache(); }, Schema::class => function(ContainerInterface $container) { // The magic happens here. We create a schema using GraphQLite SchemaFactory. $factory = new SchemaFactory($container->get(CacheInterface::class), $container); $factory->addControllerNamespace('App\\Controllers\\'); $factory->addTypeNamespace('App\\'); return $factory->createSchema(); } ]); ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Non-Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer for applications not utilizing Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ``` -------------------------------- ### Installing Laravel Altair GraphQL Client via Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.1/laravel-package.md Installs the Laravel Altair GraphQL Client package using Composer, offering an alternative web-based tool for querying the GraphQL endpoint. ```console composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Install Altair GraphQL Client with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/laravel-package.md Installs the `xkojimedia/laravel-altair-graphql` package using Composer, adding the Altair GraphQL Client web UI to a Laravel project. Altair is another popular graphical interface for interacting with GraphQL APIs. ```console $ composer require xkojimedia/laravel-altair-graphql ``` -------------------------------- ### Install GraphQLite Laravel Package (Composer) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/laravel-package.md Installs the GraphQLite Laravel package using Composer. This command adds the package as a dependency to your project. ```console $ composer require thecodingmachine/graphqlite-laravel ``` -------------------------------- ### Composer Dependencies for GraphQLite Laminas Example Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-8.0.0/other-frameworks.mdx Defines the required dependencies for the project, including thecodingmachine/graphqlite, Laminas components, mouf/picotainer for the container, and symfony/cache for caching. Also sets up PSR-4 autoloading for the App\ namespace. ```json { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^4", "laminas/laminas-diactoros": "^2", "laminas/laminas-stratigility": "^3", "laminas/laminas-httphandlerrunner": "^2", "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Composer Dependencies for Universal Service Provider Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/universal-service-providers.md Example composer.json showing the required dependencies for using the GraphQLite universal service provider, including a compatible container (Simplex) and cache provider. ```json { "require": { "mnapoli/simplex": "^0.5", "thecodingmachine/graphqlite-universal-service-provider": "^3", "thecodingmachine/symfony-cache-universal-module": "^1" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Building GraphQLite PSR-15 Middleware (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.0/other_frameworks.mdx Demonstrates how to instantiate the Psr15GraphQLMiddlewareBuilder with a GraphQL schema and create the PSR-15 middleware instance ready for integration into a compatible framework's middleware pipe. ```php // $schema is an instance of the GraphQL schema returned by SchemaFactory::createSchema (see previous chapter) $builder = new Psr15GraphQLMiddlewareBuilder($schema); $middleware = $builder->createMiddleware(); // You can now inject your middleware in your favorite PSR-15 compatible framework. // For instance: $zendMiddlewarePipe->pipe($middleware); ``` -------------------------------- ### Basic GraphQLite Schema Factory Usage (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/other-frameworks.mdx Demonstrates the basic initialization of the SchemaFactory using PSR-16 cache and PSR-11 container instances, and how to add controller and type namespaces to build the GraphQL schema. ```php use TheCodingMachine\GraphQLite\SchemaFactory; // $cache is a PSR-16 compatible cache // $container is a PSR-11 compatible container $factory = new SchemaFactory($cache, $container); $factory->addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); ``` -------------------------------- ### Install GraphQL Playground with Composer Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-6.1/laravel-package.md Use Composer to install the mll-lab/laravel-graphql-playground package, which provides a web UI for querying your GraphQL endpoint in a Laravel application. ```console $ composer require mll-lab/laravel-graphql-playground ``` -------------------------------- ### Configuring PSR-15 Middleware Builder - PHP Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/docs/other-frameworks.mdx Illustrates various configuration options available on the `Psr15GraphQLMiddlewareBuilder`, including setting the URL, modifying the Webonyx server config, setting factories, and enabling automatic persisted queries (APQ). ```php $builder->setUrl("/graphql"); // Modify the URL endpoint (defaults to /graphql) $config = $builder->getConfig(); // Returns a Webonyx ServerConfig object. // Define your own formatter and error handlers for Webonyx. $config->setErrorFormatter([ExceptionHandler::class, 'errorFormatter']); $config->setErrorsHandler([ExceptionHandler::class, 'errorHandler']); $builder->setConfig($config); $builder->setResponseFactory(new ResponseFactory()); // Set a PSR-18 ResponseFactory (not needed if you are using zend-framework/zend-diactoros ^2 $builder->setStreamFactory(new StreamFactory()); // Set a PSR-18 StreamFactory (not needed if you are using zend-framework/zend-diactoros ^2 $builder->setHttpCodeDecider(new HttpCodeDecider()); // Set a class in charge of deciding the HTTP status code based on the response. // Configure the server to use Apollo automatic persisted queries with given cache and an optional time-to-live. // See https://www.apollographql.com/docs/apollo-server/performance/apq/ $builder->useAutomaticPersistedQueries($cache, new DateInterval('PT1H')); ``` -------------------------------- ### Define Project Dependencies (composer.json) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Specifies the required libraries including graphqlite, zendframework components, picotainer, and symfony/cache for the project. ```json { "autoload": { "psr-4": { "App\\": "src/" } }, "require": { "thecodingmachine/graphqlite": "^4", "zendframework/zend-diactoros": "^2", "zendframework/zend-stratigility": "^3", "zendframework/zend-httphandlerrunner": "^1.0", "mouf/picotainer": "^1.1", "symfony/cache": "^4.2" }, "minimum-stability": "dev", "prefer-stable": true } ``` -------------------------------- ### Initializing GraphQLite SchemaFactory (PHP) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-5.0/other-frameworks.mdx Demonstrates how to create a SchemaFactory instance using a PSR-16 cache and a PSR-11 container, and how to add controller and type namespaces. ```php use TheCodingMachine\GraphQLite\SchemaFactory; // $cache is a PSR-16 compatible cache // $container is a PSR-11 compatible container $factory = new SchemaFactory($cache, $container); $factory->addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); $schema = $factory->createSchema(); ``` -------------------------------- ### Install GraphQLite Bundle with Composer (Non-Flex) Source: https://github.com/thecodingmachine/graphqlite/blob/master/website/versioned_docs/version-4.2/symfony-bundle.md Installs the GraphQLite Symfony bundle using Composer. This command is used for applications that do not use Symfony Flex. ```console $ composer require thecodingmachine/graphqlite-bundle ```