diff --git a/website/docs/other-frameworks.mdx b/website/docs/other-frameworks.mdx index 71cc9de3aa..6ae053e3ab 100644 --- a/website/docs/other-frameworks.mdx +++ b/website/docs/other-frameworks.mdx @@ -102,15 +102,63 @@ $result = GraphQL::executeQuery($schema, $query, null, new Context(), $variableV The smallest working example using no framework is: -```php +```json title="composer.json" +{ + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "require": { + "thecodingmachine/graphqlite": "^6", + "mouf/picotainer": "^1.1", + "symfony/cache": "^4.2" + } +} +``` + +```php title="src/Controllers/MyController.php" + function() { + return new MyController(); + }, +]); + $factory = new SchemaFactory($cache, $container); $factory->addControllerNamespace('App\\Controllers\\') ->addTypeNamespace('App\\'); @@ -129,6 +177,23 @@ header('Content-Type: application/json'); echo json_encode($output); ``` +Then to install dependencies and run the server: +```console +$ composer install +$ php -S localhost:8080 +``` + +And check that it works: +```console +$ curl -X POST -d '{"query":"{ hello(name: \"World\") }"}' -H "Content-Type: application/json" http://localhost:8080 +``` + +If all is working correctly this should output: +```json +{"data":{"hello":"Hello World"}} +``` + + ## PSR-15 Middleware When using a framework, you will need a way to route your HTTP requests to the `webonyx/graphql-php` library.