Skip to content

A framework-agnostic, ORM library for interacting and retrieving data from the Hashnode GraphQL API. (Requires PHP 7.4)

License

Notifications You must be signed in to change notification settings

oliverearl/php-hashnode

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


PHP Hashnode

Unofficial Hashnode API Wrapper for PHP

A lightweight, object-oriented library for interacting with Hashnode's GraphQL API.
Explore the docs »

View Examples · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

Installation

  1. Clone the repo

    git clone https://github.com/oliverearl/php-hashnode.git
  2. Install Composer packages

    composer install

This library will be made available for install via Composer once it has reached a more complete state.

Usage

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.

Roadmap

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).

Contributing

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.

Particularly welcome contributions

  • 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.

Instructions

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Testing

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.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Oliver Earl - oliver@oliverearl.co.uk

Project Link: https://github.com/oliverearl/php-hashnode

Acknowledgements

About

A framework-agnostic, ORM library for interacting and retrieving data from the Hashnode GraphQL API. (Requires PHP 7.4)

Topics

Resources

License

Stars

Watchers

Forks

Languages