diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 83b76ca61f..86083f6218 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -95,7 +95,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - example: ['no-framework'] + example: ['no-framework', 'psr-15'] fail-fast: false steps: - name: "Checkout" diff --git a/examples/psr-15/README.md b/examples/psr-15/README.md new file mode 100644 index 0000000000..61f563abe9 --- /dev/null +++ b/examples/psr-15/README.md @@ -0,0 +1,11 @@ +PSR-15 Integration Example +========================== + +``` +composer install +php -S 127.0.0.1:8080 +``` + +``` +curl -X POST -d '{"query":"{ hello(name: \"World\") }"}' -H "Content-Type: application/json" http://localhost:8080/graphql +``` diff --git a/examples/psr-15/composer.json b/examples/psr-15/composer.json new file mode 100644 index 0000000000..5f08cabac3 --- /dev/null +++ b/examples/psr-15/composer.json @@ -0,0 +1,31 @@ +{ + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "require": { + "thecodingmachine/graphqlite": "@dev", + "laminas/laminas-diactoros": "^2", + "laminas/laminas-stratigility": "^3", + "laminas/laminas-httphandlerrunner": "^2", + "mouf/picotainer": "^1.1", + "symfony/cache": "^4.2" + }, + "repositories": [ + { + "type": "path", + "url": "tmp-graphqlite", + "options": { + "symlink": true + } + } + ], + "scripts": { + "symlink-package": [ + "rm -rf tmp-graphqlite && ln -s -f ../../ tmp-graphqlite" + ], + "pre-install-cmd": "@symlink-package", + "pre-update-cmd": "@symlink-package" + } +} diff --git a/examples/psr-15/config/container.php b/examples/psr-15/config/container.php new file mode 100644 index 0000000000..3ab85badc2 --- /dev/null +++ b/examples/psr-15/config/container.php @@ -0,0 +1,40 @@ + 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 FilesystemCache(); + }, + 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(); + }, + // We declare the controller in the container. + MyController::class => function() { + return new MyController(); + }, +]); + diff --git a/examples/psr-15/index.php b/examples/psr-15/index.php new file mode 100644 index 0000000000..0c44bb3525 --- /dev/null +++ b/examples/psr-15/index.php @@ -0,0 +1,30 @@ +get(MiddlewarePipe::class), + new SapiStreamEmitter(), + $serverRequestFactory, + $errorResponseGenerator +); +$runner->run(); + diff --git a/examples/psr-15/src/Controllers/MyController.php b/examples/psr-15/src/Controllers/MyController.php new file mode 100644 index 0000000000..93f3a185a8 --- /dev/null +++ b/examples/psr-15/src/Controllers/MyController.php @@ -0,0 +1,13 @@ +