Skip to content

Instantly share code, notes, and snippets.

@hank
Created January 10, 2025 08:23
Show Gist options
  • Save hank/9e9a678c0ba58292b7f4870e219671e9 to your computer and use it in GitHub Desktop.
Save hank/9e9a678c0ba58292b7f4870e219671e9 to your computer and use it in GitHub Desktop.
Querying Hardcover using GraphQL
// Uses "carnage/php-graphql-client": "^1.14" in composer
function QueryHardcover() {
$client = new GraphQL\Client(
'https://api.hardcover.app/v1/graphql',
['Authorization' => "Bearer meeeeee" ]
);
$gql = <<<QUERY
{
list_books(where: {list_id:{_eq:1}} order_by:{book:{title:asc}}) {
book_id, position, book {
id, title, image {
url, width, height
}, pages, rating, slug
contributions { author { name } }
}
}
}
QUERY;
try {
$results = $client->runRawQuery($gql);
}
catch (GraphQL\Exception\QueryError $exception) {
// Catch query error and desplay error details
print_r($exception->getErrorDetails());
return;
}
// Display part of the returned results of the object
return $results->getData();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment