When querying globals from the GraphiQl interface, from my frontend application, or from an API explorer like Insomnia, CraftQL returns an error Trying to get property of non-object
.
I am running Craft 3.1.8 and CraftQL 1.3.1.
query getGlobalTest {
globals {
... on GlobalsSet {
test {
... on Test {
test
}
}
}
}
}
The error occurs in vendor/markhuot/craftql/src/Types/Query.php
on line 215.
foreach ($setIds as $id) {
$set = \Craft::$app->globals->getSetById($id, $siteId);
$sets[$set->handle] = $set; <-- Error line
}
This happens when querying anything in globals. I read somewhere that this has to do with Craft updating to UUIDs in Craft 3.1, however, I am not sure.
That error just means your getSetById() query returned nothing. You wouldn't pass a UUID to that either. It expects an int. Are you sure your $siteId variable is correct? If you want to avoid errors, you could add this to your code:
foreach ($setIds as $id) {
if ($set = \Craft::$app->globals->getSetById($id, $siteId)) {
$sets[$set->handle] = $set;
}
}
But I would suggest taking a look a the $siteId, or removing it altogether.