zestic / webonxy-middleware
Webonxy GraqhQL middleware
v1.1.1
2024-11-07 15:11 UTC
Requires
- php: ^8.3
- firebase/php-jwt: ^6.1.0
- laminas/laminas-cache: ^4.0
- laminas/laminas-cache-storage-adapter-filesystem: ^2.4 || ^3.0
- laminas/laminas-servicemanager: ^4.0
- nesbot/carbon: ^2.16
- psr/container: ^1.0 || ^2.0
- psr/http-server-middleware: ^1.0
- psr/log: ^2.0 || ^3.0
- webonyx/graphql-php: ^15.0.0
Requires (Dev)
- laminas/laminas-diactoros: ^2.4
- phpspec/prophecy: ~1.0
- phpunit/phpunit: ^10.4@dev
README
To use the middleware in Laminas Mezzio, configure the factories
in config/autoload/dependencies.global.php
return [ 'dependencies' => [ 'factories' => [ \GraphQL\Server\StandardServer::class => \Xaddax\GraphQL\Factory\StandardServerFactory::class, \Zestic\GraphQL\Middleware\GraphQLMiddleware::class => \Xaddax\GraphQL\Factory\GraphQLMiddlewareFactory::class, ], ], ];
Add configuration in config/autoload/graphql.global.php
return [ 'graphQL' => [ 'middleware' => [ 'allowedHeaders' => [ 'application/graphql', 'application/json', ], ], 'schema' => \Path\To\Schema::class, // optional, defaults to webonxy Schema 'schemaConfig' => [], // optional, if not configured expected in Schema class constructor 'server' => \Path\To\Server::class, // not yet implemented, defaults to webonxy StandardServer 'serverConfig' => [ 'context' => \Zestic\GraphQL\Context\TokenContext::class 'schema' => \Path\To\Your\Schema::class, ], ], ];
see the WebOnyx Server Configuration Documentation for the full options for the server config.
You'll need to set up the route. In config/routes.php
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void { $app->post('/graphql', \Zestic\GraphQL\Middleware\GraphQLMiddleware::class, 'graphql'); };
Schema Definition Language
You can also use a Schema Definition Language as discussed in the WebOnxy documentation.
In config/autoload/graphql.global.php
change the schema in the serverConfig
to generatedSchema
return [ 'graphQL' => [ 'serverConfig' => [ 'schema' => 'generatedSchema', ], ], ];
Then inside of the graphQL
config add the generatedSchema
configuration
return [ 'graphQL' => [ 'generatedSchema' => [ 'parserOptions' => [ 'experimentalFragmentVariables' => true, // to parse fragments 'noLocation' => false, // default, set true for development ], 'cache' => [ 'alwaysEnabled' => false, // default, set to true to cache when the system cache is not enabled 'directoryChangeFilename' => 'directory-change-cache.php', // default 'schemaCacheFilename' => 'schema-cache.php', // default ], 'schemaDirectories' => [ '/full/path/to/schema-directory-1', '/full/path/to/schema-directory-2', ], ], ], ];
See the documentation for
parserOptions
The cached data is stored in data/cache/graphql
.