A lightweight, object-oriented library for interacting with Hashnode's GraphQL API.
Explore the docs »
View Examples
·
Report Bug
·
Request Feature
To get a local copy up and running follow these simple steps.
-
Clone the repo
git clone https://github.com/oliverearl/php-hashnode.git
-
Install Composer packages
composer install
This library will be made available for install via Composer once it has reached a more complete state.
After installation, the library is ready to use out-of-the-box. A client instance and GraphQL root query object can be made like thus:
$client = new Hashnode();
$query = new RootQuery();
If you wish to specify an override for the default Hashnode endpoint, and/or specify your Hashnode API token (if you need one, you can get one here) you can add them as constructor parameters. You don't need an API token for most operations at present.
$client = new Hashnode('https://some-alternative-endpoint.hashnode.com', [
'Authorization' => 'my-api-key-goes-here'
]);
Remember when interacting with GraphQL APIs, you have to specifically indicate what information you want to request. If you wanted to request a stories feed with a title, date, and the author's username, you could do something like this:
(Also, this is assuming you utilise 'use statements' and don't have to resolve namespaces fully.)
$query->selectStoriesFeed((new RootStoriesFeedArgument())->setType('NEW'))
->selectTitle()
->selectDateAdded()
->selectAuthor((new AuthorArgument()))
->selectUsername();
$results = $client->runQuery($query->getQuery())->getData();
For more examples, please refer to the Documentation or check available examples.
The following is on the roadmap for upcoming releases:
-
API behaviours that require an API key (creating, updating, deleting)
-
Changes to make the library easier to use and potentially less dependent on the underlying GraphQL libraries
-
Cleaner, less lasagna-like code
-
Integration PHPUnit tests
Also, see the open issues for a list of user-proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
-
Bugfixes and beneficiary changes to existing functionality.
-
New functionality that fulfills unimplemented areas of the API.
-
Enhancements to existing or production of additional PHPUnit tests.
-
Documentation, both in the source code and in the
docs
directory. -
Examples of the library in use within the
examples
directory.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
The suite of PHPUnit tests can be run with composer run test
at your terminal, assuming a full installation of Composer.
Alternatively, you can retrieve easy-to-read testdox by running composer run testdox
.
Distributed under the MIT License. See LICENSE
for more information.
Oliver Earl - [email protected]
Project Link: https://github.com/oliverearl/php-hashnode