1. Go to this page and download the library: Download chemisus/graphql library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chemisus / graphql example snippets
class BookWirer implements Wirer {
function wire(Document $document) {
$document->coerce('Book', new CallbackCoercer(function (Node $node, Book $value) {
return (object)[
'id' => $book->getId(),
'title' => $book->getTitle(),
'authorId' => $book->getAuthorId(),
];
});
}
}
class PersonWirer implements Wirer {
function wire(Document $document) {
$document->coerce('Person', new CallbackCoercer(function (Node $node, Person $value) {
return (object)[
'id' => $person->getId(),
'name' => $person->getName(),
];
});
}
}
class QueryBookWirer implements Wirer {
function wire(Document $document) {
$document->fetcher('Query', 'book', new CallbackFetcher(function (Node $node) {
$ids = $node->arg('id');
return [BookRepository::getBook($id)];
});
$document->resolve('Query', 'book', new CallbackResolver(function (Node $node, $parent, $value) {
$books = $node->getItems();
return array_shift($books);
});
}
}