Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/simpod/php-graphql-request-factory

GraphQL PSR-7 Request Factory
https://github.com/simpod/php-graphql-request-factory

client graphql graphql-request-factory hacktoberfest php psr-17 psr-18 psr-7

Last synced: 5 days ago
JSON representation

GraphQL PSR-7 Request Factory

Awesome Lists containing this project

README

        

# PHP GraphQL Request Factory

[![GitHub Actions][GA Image]][GA Link]
[![Code Coverage][Coverage Image]][CodeCov Link]
[![Downloads][Downloads Image]][Packagist Link]
[![Packagist][Packagist Image]][Packagist Link]
[![Infection MSI][Infection Image]][Infection Link]

This factory creates PSR-7 GraphQL Request through PSR-17 message factories
that you can be passed to PSR-18 client.

## Installation

Add as [Composer](https://getcomposer.org/) dependency:

```sh
composer require simpod/graphql-request-factory
```

## Usage

```php
createRequest(
'https://localhost/graphql',
<<<'GRAPHQL'
query GetHuman($id: ID!) {
human(id: $id) {
name
appearsIn
starships {
name
}
}
}
GRAPHQL,
['id' => 1]
);
```

You can pass `$query` either as a `string` or PSR-7 `StreamInterface`.

### Mkay, but what should I do with the request then?

You can pass it to any HTTP client supporting PSR-7. It's up to you what client you decide to use.

#### Guzzle

http://docs.guzzlephp.org/en/stable/quickstart.html#sending-requests

```php
$response = $client->send($request);
```

#### PSR-18 Client (eg. HTTPPlug)

https://www.php-fig.org/psr/psr-18/#clientinterface

```php
$response = $client->sendRequest($request);
```

[GA Image]: https://github.com/simPod/PHP-GraphQL-Request-Factory/workflows/Continuous%20Integration/badge.svg
[GA Link]: https://github.com/simPod/PHP-GraphQL-Request-Factory/actions?query=workflow%3A%22Continuous+Integration%22+branch%3Amaster
[Coverage Image]: https://codecov.io/gh/simPod/PHP-GraphQL-Request-Factory/branch/master/graph/badge.svg
[CodeCov Link]: https://codecov.io/gh/simPod/PHP-GraphQL-Request-Factory/branch/master
[Downloads Image]: https://poser.pugx.org/simpod/graphql-request-factory/d/total.svg
[Packagist Image]: https://poser.pugx.org/simpod/graphql-request-factory/v/stable.svg
[Packagist Link]: https://packagist.org/packages/simpod/graphql-request-factory
[Infection Image]: https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2FsimPod%2FPHP-GraphQL-Request-Factory%2Fmaster
[Infection Link]: https://infection.github.io