wappcode/graphql-basic-client

There is no license information available for the latest version (1.0.1) of this package.

1.0.1 2023-12-06 18:44 UTC

This package is not auto-updated.

Last update: 2024-05-08 20:41:46 UTC


README

Allows making queries to a graphql API.

Gets an array as result

Requirements

Needs curl extension enabled

Install

composer require wappcode/graphql-basic-client

Use

Query

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

Mutation

$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);