wappcode / graphql-basic-client

此包最新版本(1.0.2)的许可证信息不可用。

1.0.2 2024-06-18 22:09 UTC

This package is not auto-updated.

Last update: 2024-09-24 23:19:17 UTC


README

允许对 graphql API 进行查询。

以数组形式返回结果

需求

需要启用 curl 扩展

安装

composer require wappcode/graphql-basic-client

使用

查询

$client = new GQLClient("http://graphql-api");
        $query = '
        query  {
            users {
            id
            name
            firstname
            lastname
            email
            }
        }
        ';
        $result = $client->execute($query);

突变

$client = new GQLClient("http://graphql-api");
	$query = '
	mutation MutationCreateUser($input: UserInput) {
		user: createUser(input: $input) {
          id
		  name
		  firstname
		  lastname
		  email
		}
	  }
	';
	$variables = [
		"input" => [
			"firstname" => "John",
			"lastname" => "Doe",
			"email" => "johndoe@demo.com"
		]
	];
	$headers = [
		"Authorization: Bearer jwt"
	];
	$result = $client->execute($query, $variables, $headers);