curfle / package-leuchtturm
There is no license information available for the latest version (v0.3.0) of this package.
Package that supports the creation of a GraphQL api within a curfle project
v0.3.0
2022-03-09 23:40 UTC
Requires
- php: >=8.0
- curfle/framework: ~0
- joonlabs/php-graphql: ~2
Requires (Dev)
- phpunit/phpunit: ^9.3.3
README
Leuchtturm is a package to help you easily build CRUDA-Operations (create
, read
, update
, delete
and all
) based GraphQL-apis with joonlabs\php-graphql
within Curfle
.
Installation
composer require curfle/package-leuchtturm
Example
use GraphQL\Servers\Server; use GraphQL\Schemas\Schema; use GraphQL\Types\GraphQLString; use GraphQL\Types\GraphQLObjectType; use GraphQL\Fields\GraphQLTypeField; // build the query type $manager = new \Leuchtturm\LeuchtturmManager(); $manager->setVocab(new \Leuchtturm\Vocab\German()); // TODO: should never use create again (only create, read, update, delete) $QueryType = new GraphQLObjectType("Query", "Root Query", function () use($manager){ return [ $manager->R(\Examples\Models\Job::class)->build(), $manager->R(\Examples\Models\Login::class)->build(), $manager->R(\Examples\Models\Benutzer::class)->onlyOwner()->build(), // only the owner may read this field $manager->R(\Examples\Models\Rolle::class)->build(), $manager->A(\Examples\Models\Job::class)->build(), $manager->A(\Examples\Models\Login::class)->build(), $manager->A(\Examples\Models\Benutzer::class)->build(), $manager->A(\Examples\Models\Rolle::class)->build(), ]; }); $MutationType = new GraphQLObjectType("Mutation", "Mutation Query", function () use($manager){ return [ // all fields are protected by the default guardian $manager->C(\Examples\Models\Job::class)->guardian()->build(), $manager->C(\Examples\Models\Login::class)->guardian()->build(), $manager->C(\Examples\Models\Benutzer::class)->guardian()->build(), $manager->C(\Examples\Models\Rolle::class)->guardian()->build(), $manager->U(\Examples\Models\Job::class)->guardian()->build(), $manager->U(\Examples\Models\Login::class)->guardian()->build(), $manager->U(\Examples\Models\Benutzer::class)->guardian()->build(), $manager->U(\Examples\Models\Rolle::class)->guardian()->build(), $manager->D(\Examples\Models\Job::class)->guardian()->build(), $manager->D(\Examples\Models\Login::class)->guardian()->build(), $manager->D(\Examples\Models\Benutzer::class)->guardian()->onlyOwner()->build(), // also the owner may delete entries via this field $manager->D(\Examples\Models\Rolle::class)->guardian()->build(), ]; }); // build the schema $schema = new Schema($QueryType, $MutationType); // start a server $server = new Server($schema); $server->listen();