• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

softonic/graphql-client: PHP Client for GraphQL

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

softonic/graphql-client

开源软件地址(OpenSource Url):

https://github.com/softonic/graphql-client

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

PHP GraphQL Client

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads Average time to resolve an issue Percentage of issues still open

PHP Client for GraphQL

Installation

Via composer:

composer require softonic/graphql-client

Documentation

To instantiate a client with an OAuth2 provider:

<?php

$options = [
    'clientId' => 'myclient',
    'clientSecret' => 'mysecret',
];

$provider = new Softonic\OAuth2\Client\Provider\Softonic($options);

$config = ['grant_type' => 'client_credentials', 'scope' => 'myscope'];

$cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();

$client = \Softonic\GraphQL\ClientBuilder::buildWithOAuth2Provider(
    'https://catalog.swarm.pub.softonic.one/graphql',
    $provider,
    $config,
    $cache
);

// Query Example
$query = <<<'QUERY'
query GetFooBar($idFoo: String, $idBar: String) {
  foo(id: $idFoo) {
    id_foo
    bar (id: $idBar) {
      id_bar
    }
  }
}
QUERY;
$variables = ['idFoo' => 'foo', 'idBar' => 'bar'];
$response = $client->query($query, $variables);

// Mutation Example
$mutation = <<<'MUTATION'
mutation ($foo: ObjectInput!){
  CreateObjectMutation (object: $foo) {
    status
  }
}
MUTATION;
$variables = [
    'foo' => [
        'id_foo' => 'foo', 
        'bar' => [
            'id_bar' => 'bar'
        ]
    ]
];
$response = $client->query($mutation, $variables);

To instantiate a client without OAuth2:

<?php
$client = \Softonic\GraphQL\ClientBuilder::build('https://catalog.swarm.pub.softonic.one/graphql');

$query = <<<'QUERY'
query GetFooBar($idFoo: String, $idBar: String) {
  foo(id: $idFoo) {
    id_foo
    bar (id: $idBar) {
      id_bar
    }
  }
}
QUERY;

$variables = [
    'idFoo' => 'foo',
    'idBar' => 'bar',
];
$response = $client->query($query, $variables);

Testing

softonic/graphql-client has a PHPUnit test suite and a coding style compliance test suite using PHP CS Fixer.

To run the tests, run the following command from the project folder.

$ docker-compose run test

To run interactively using PsySH:

$ docker-compose run psysh

License

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap