Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Craft throws invalid access token error when clicking on GraphQL "Public Schema" #11218

Closed
richhayler opened this issue May 13, 2022 · 8 comments

Comments

@richhayler
Copy link

richhayler commented May 13, 2022

What happened?

Description

Craft throws an error when clicking on the default GraphQL "Public Schema" due to invalid access token

Steps to reproduce

  1. Navigate to "GraphQL" > "Schemas"2.
  2. Click "Public Schema"3.

CleanShot 2022-05-13 at 16 08 59@2x

Actual behavior

Invalid Argument – yii\base\InvalidArgumentException
Invalid access token

CleanShot 2022-05-13 at 16 12 40@2x

Craft CMS version

4.0.2

PHP version

8.1.5

Operating system and version

Linux 5.4.0

Database type and version

MySQL 8.0.29

Image driver and version

Imagick 3.6.0

@richhayler richhayler changed the title [4.x]: Craft throws an error when clicking on GraphQL "Public Schema" [4.x]: Craft throws invalid access token error when clicking on GraphQL "Public Schema" May 13, 2022
@brandonkelly
Copy link
Member

Can you find that error in storage/logs/ and post the stack trace that follows it?

@richhayler
Copy link
Author

yii\base\InvalidArgumentException: Invalid access token in /craft/vendor/craftcms/cms/src/services/Gql.php:792
Stack trace:
#0 /craft/vendor/craftcms/cms/src/controllers/GraphqlController.php(562): craft\services\Gql->getTokenByAccessToken()
#1 [internal function]: craft\controllers\GraphqlController->actionEditPublicSchema()
#2 /craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#3 /craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#4 /craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#5 /craft/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction()
#6 /craft/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction()
#7 /craft/vendor/craftcms/cms/src/web/Application.php(286): yii\web\Application->handleRequest()
#8 /craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#9 /craft/web/index.php(19): yii\base\Application->run()
#10 {main}

@danielvanc
Copy link

danielvanc commented May 16, 2022

I am having the same issue as well. Also running the same versions of Craft, PHP, and MySQL as OP. Any updates on this?

@danielvanc
Copy link

danielvanc commented May 16, 2022

Here's is my stack trace from storage/logs

Screenshot 2022-05-16 at 10 59 09

@angrybrad
Copy link
Member

From a fresh Craft 4 installation, I'm able to reproduce this by deleting the auto-generated public token in the gqltokens table.

If I also delete the public schema row in the gqlschemas table, then reload the schema page in the control panel, a new public schema is auto-generated, but this doesn't happen for the public token.

@brandonkelly
Copy link
Member

I was able to reproduce when the token was present in the project config, but not in the database, and believe it’s due to a project config service change in Craft 4, where changes are only processed if the value actually changes. craft\services\Gql::getPublicToken() was detecting that a public token didn’t exist in the DB, and went to create one. But saveToken() has a special case for the public token, where instead of saving it to the DB directly, it writes it out to the project config, and defers the DB part to handleChangedPublicToken(). Except handleChangedPublicToken() isn’t getting called if the token value hasn’t changed.

Anyway, I’ve fixed this for the next release by moving away from storing the public token in the database altogether, as there’s really no point in doing that if the exact same config data is already in the project config.

To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 4.0.2" and run composer update.

@danielvanc
Copy link

Thanks allot @brandonkelly I can confirm, my end that that fix worked, great stuff 👍🏼

@brandonkelly
Copy link
Member

Craft 4.0.3 is out now with that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants