[4.x]: Issue with GraphQL API
What happened?
Description
After the upgrade from Craft 3 to Craft 4, there has been an issue with the GraphQL playground.
Steps to reproduce
- /
Expected behavior
Open the playground
Actual behavior
Error page showing that there has been an internal server error
Craft CMS version
4.0.2
PHP version
8.0.17
Operating system and version
Linux 4.14.275-207.503.amzn2.x86_64
Database type and version
MySQL 8.0.25
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.0-16)
Installed plugins and versions
- Amazon S3 - v2.0.0 Redactor - v3.0.0
By “playground” are you referring to the built-in GraphiQL IDE (/admin/graphiql)? Working fine on my end.
If you enable Dev Mode, you should be able to see the exact error that’s occurring. Or search the latest storage/logs/web-XXXX-XX-XX.log for [web.ERROR] after the error occurs.
@brandonkelly Apologies for the late reply, lost track of the issue and wasn't able to pull the logs up until now. Here are the logs we found:
2022-06-16 12:33:12 [web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key 38 in /app/vendor/craftcms/cms/src/services/Gql.php:1462
Stack trace:
#0 /app/vendor/craftcms/cms/src/web/ErrorHandler.php(77): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/app/vendor/cra...', 1462)
#1 /app/vendor/craftcms/cms/src/services/Gql.php(1462): craft\web\ErrorHandler->handleError(2, 'Undefined array...', '/app/vendor/cra...', 1462)
#2 /app/vendor/craftcms/cms/src/services/Gql.php(660): craft\services\Gql->_getSectionSchemaComponents()
#3 /app/vendor/twig/twig/src/Extension/CoreExtension.php(1607): craft\services\Gql->getAllSchemaComponents()
#4 /app/vendor/craftcms/cms/src/helpers/Template.php(101): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\services\Gql), 'getAllSchemaCom...', Array, 'any', false, false)
#5 /app/storage/runtime/compiled_templates/9a/9a95b549e44d51abb7b77b9ebe2a81186d93dd696134aba22af3d9e1e1885822.php(117): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\services\Gql), 'getAllSchemaCom...', Array)
#6 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_03d6af38c3b79aefba2e90cbeeba061453c9ee1e6dab4408da49555bf48838da->block_content(Array, Array)
#7 /app/storage/runtime/compiled_templates/90/9087011f071c4958d23826f7fe1a0eef13ec3f9b862888083c35843c25408960.php(566): Twig\Template->displayBlock('content', Array, Array)
#8 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_c8f5e60c93ab3496177f4278a600548eec845dab6d87e9df007543095aebd1d3->block_main(Array, Array)
#9 /app/storage/runtime/compiled_templates/90/9087011f071c4958d23826f7fe1a0eef13ec3f9b862888083c35843c25408960.php(358): Twig\Template->displayBlock('main', Array, Array)
#10 /app/vendor/twig/twig/src/Template.php(171): __TwigTemplate_c8f5e60c93ab3496177f4278a600548eec845dab6d87e9df007543095aebd1d3->block_body(Array, Array)
#11 /app/storage/runtime/compiled_templates/b0/b0434066058cdff4a28f359b3ca678f3c1817dd361031435de19335e858c92b0.php(94): Twig\Template->displayBlock('body', Array, Array)
#12 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7742cd87b02442bc2cfc4524ea59a2e908ed7a56604188cfc05877417076fa91->doDisplay(Array, Array)
#13 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#14 /app/storage/runtime/compiled_templates/75/7575e42eb8f6f87f5a48e5c5dc61300df717b26cd18ce637d4e418102c6a2630.php(56): Twig\Template->display(Array, Array)
#15 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_49d6bd7f3a30108376c8e20b0af8b59258edc398c69d985ed9e4ebc6ddba7c5b->doDisplay(Array, Array)
#16 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#17 /app/storage/runtime/compiled_templates/90/9087011f071c4958d23826f7fe1a0eef13ec3f9b862888083c35843c25408960.php(172): Twig\Template->display(Array, Array)
#18 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_c8f5e60c93ab3496177f4278a600548eec845dab6d87e9df007543095aebd1d3->doDisplay(Array, Array)
#19 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#20 /app/storage/runtime/compiled_templates/9a/9a95b549e44d51abb7b77b9ebe2a81186d93dd696134aba22af3d9e1e1885822.php(70): Twig\Template->display(Array, Array)
#21 /app/vendor/twig/twig/src/Template.php(394): __TwigTemplate_03d6af38c3b79aefba2e90cbeeba061453c9ee1e6dab4408da49555bf48838da->doDisplay(Array, Array)
#22 /app/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#23 /app/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#24 /app/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#25 /app/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#26 /app/vendor/craftcms/cms/src/web/View.php(414): Twig\Environment->render('graphql/schemas...', Array)
#27 /app/vendor/craftcms/cms/src/web/View.php(467): craft\web\View->renderTemplate('graphql/schemas...', Array)
#28 /app/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(52): craft\web\View->renderPageTemplate('graphql/schemas...', Array, 'cp')
#29 /app/vendor/yiisoft/yii2/web/Response.php(1095): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#30 /app/vendor/craftcms/cms/src/web/Response.php(286): yii\web\Response->prepare()
#31 /app/vendor/yiisoft/yii2/web/Response.php(339): craft\web\Response->prepare()
#32 /app/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#33 /app/web/index.php(21): yii\base\Application->run()
#34 {main} {"memory":10706776,"exception":"[object] (yii\\base\\ErrorException(code: 2): Undefined array key 38 at /app/vendor/craftcms/cms/src/services/Gql.php:1462)"}
It looks like you (somehow) have a section that doesn’t have any entry types. Not possible from the control panel, but maybe it could happen from a project config merge conflict or something like that.
The relevant code hasn’t changed in Craft 4, so I’ve made it more defensive for this possibility for the next Craft 3 and 4 releases.
You can test the fix by changing your craftcms/cms requirement in composer.json to "dev-develop as 4.0.4" and running composer update.
Craft 3.7.45 and 4.0.5 are out now with that fix.
Apologies for not responding to your previous message!
Thanks for the help!