You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: I recently had a deployment fail in production due to an error Changes to the project config are not possible while in read-only mode. I tracked this down to a public GQL schema missing its meta:__names__ key in project.yaml.
To figure out why that meta name key was missing, I did some digging and here's what I found:
When running project-config/rebuild in a project without any public GQL tokens or schemas, Craft will output an empty publicToken definition to the project.yaml file (via ProjectConfig::_getGqlData()).
Later, if the project config files w/ the above publicToken are re-applied using project-config/apply --force, in an environment where admin changes are allowed and there are no public schemas, Craft will automatically create a default, public GQL schema (probably via Gql::_createPublicToken()?), and save it to the config/project/graphql/schemas folder.
However, and crucially, this schema will not have an entry created in the meta:__names__ section in project.yaml.
The missing meta name leads to the Changes to the project config are not possible while in read-only mode. error, when attempting to apply the YAML files in an environment where admin changes are disallowed.
Additional context: I don't use GraphQL and the project has been bootstrapped with the enableGql setting set to false. That's not directly relevant to the issue (it happens with or without GraphQL enabled), but I thought it was worth mentioning (ideally, I think Craft shouldn't create that public schema in the first place, when GQL is disabled?).
Run ddev craft project-config/rebuild to rebuild YAML files. Observe that Craft has created an empty publicToken in project.yaml.
Run ddev craft project-config/apply --force. Observe that a public schema has been created, but with no entry in meta:__names__.
Disable allowAdminChanges, and run ddev craft project-config/apply --force again. (Alternatively; push and run project-config/apply in a production environment). Observe the Changes to the project config are not possible while in read-only mode error.
Expected behavior
Actual behavior
Craft CMS version
4.5.11.1
PHP version
8.1.26
Operating system and version
macOS 12.6, DDEV v1.22.5
Database type and version
Tested on both MariaDB 10.5.21 (DDEV default) and MySQL 8.0.33
Image driver and version
No response
Installed plugins and versions
None
The text was updated successfully, but these errors were encountered:
mmikkel
changed the title
[4.x]: Corrupted project.yaml file due to auto-created public GQL schema missing from meta names array
[4.x]: Invalid project.yaml file due to auto-created public GQL schema missing from meta names array
Dec 11, 2023
What happened?
Description
Context: I recently had a deployment fail in production due to an error
Changes to the project config are not possible while in read-only mode.
I tracked this down to a public GQL schema missing itsmeta:__names__
key inproject.yaml
.To figure out why that meta name key was missing, I did some digging and here's what I found:
project-config/rebuild
in a project without any public GQL tokens or schemas, Craft will output an emptypublicToken
definition to theproject.yaml
file (viaProjectConfig::_getGqlData()
).Here's what that looks like:
publicToken
are re-applied usingproject-config/apply --force
, in an environment where admin changes are allowed and there are no public schemas, Craft will automatically create a default, public GQL schema (probably viaGql::_createPublicToken()
?), and save it to theconfig/project/graphql/schemas
folder.However, and crucially, this schema will not have an entry created in the
meta:__names__
section inproject.yaml
.Changes to the project config are not possible while in read-only mode.
error, when attempting to apply the YAML files in an environment where admin changes are disallowed.Additional context: I don't use GraphQL and the project has been bootstrapped with the
enableGql
setting set tofalse
. That's not directly relevant to the issue (it happens with or without GraphQL enabled), but I thought it was worth mentioning (ideally, I think Craft shouldn't create that public schema in the first place, when GQL is disabled?).Steps to reproduce
ddev craft project-config/rebuild
to rebuild YAML files. Observe that Craft has created an emptypublicToken
inproject.yaml
.ddev craft project-config/apply --force
. Observe that a public schema has been created, but with no entry inmeta:__names__
.allowAdminChanges
, and runddev craft project-config/apply --force
again. (Alternatively; push and runproject-config/apply
in a production environment). Observe theChanges to the project config are not possible while in read-only mode
error.Expected behavior
Actual behavior
Craft CMS version
4.5.11.1
PHP version
8.1.26
Operating system and version
macOS 12.6, DDEV v1.22.5
Database type and version
Tested on both MariaDB 10.5.21 (DDEV default) and MySQL 8.0.33
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: