Created
January 10, 2025 08:23
-
-
Save hank/9e9a678c0ba58292b7f4870e219671e9 to your computer and use it in GitHub Desktop.
Querying Hardcover using GraphQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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