fox-hound-ltd/mixture-api-client

GraphQL & REST API Client

0.1.0 2018-11-08 09:22 UTC

This package is not auto-updated.

Last update: 2024-09-21 08:15:52 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

概要

GraphQLとRESTに対応したClientライブラリ

PHP Client for GraphQL & REST

GuzzleHttp Baseベース

インストール

Composerを利用

$ composer require fox-hound-ltd/mixture-api-client

利用方法サンプル

シンプルパターン

<?php
use MixtureApiClient\ClientBuilder;

$client = ClientBuilder::build(
    'https://hogehoge.com/graphql'
);

$query = <<<'QUERY'
query foo(id: 11){
 id
 name
}
QUERY;

$response = $client->query($query);

JsonWebTokenを利用する場合

<?php
use MixtureApiClient\ClientBuilder;
use MixtureApiClient\JWT;

$jwt= new JWT();

$payload['secret_key'] = 'fiwivkbbeec1e958a6c5dd31336242607c0887754b1d43ebf071fb2890533d611a';

$headers = [
    'Authorization' => $jwt->makeToken('secret', $payload),
];

$config = ['headers' => $headers];

$client = ClientBuilder::build(
    'https://hogehoge.com/graphql',
    $config
);

$query = <<<'QUERY'
query GetHoge($target_id: ID, $member_name: String) {
  foo(id: $target_id) {
    id_foo
    bar (name: $member_name) {
      id_bar
    }
  }
}
QUERY;

$variables = [
    'target_id' => 11,
    'member_name' => 'bar',
];
$response = $client->query($query, $variables);

テストについて

$ composer test

ライセンス

The Apache 2.0 license. Please see LICENSE for more information.