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]: Invalid project.yaml file due to auto-created public GQL schema missing from meta names array #14018

Closed
mmikkel opened this issue Dec 11, 2023 · 2 comments
Assignees

Comments

@mmikkel
Copy link
Contributor

mmikkel commented 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 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:

  1. 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()).

Here's what that looks like:

graphql:
  publicToken:
    enabled: false
    expiryDate: null
  1. 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.

  1. 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?).

Steps to reproduce

  1. Bootstrap a new Craft project using the official quick-start directions
  2. Do not visit the GraphQL section in the CP
  3. Run ddev craft project-config/rebuild to rebuild YAML files. Observe that Craft has created an empty publicToken in project.yaml.
  4. Run ddev craft project-config/apply --force. Observe that a public schema has been created, but with no entry in meta:__names__.
  5. 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
@mmikkel 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
@brandonkelly brandonkelly self-assigned this Dec 11, 2023
@brandonkelly
Copy link
Member

Thanks for reporting that! Just added some code to guard against updating meta.__names__ when in read-only mode, for the next release.

@brandonkelly
Copy link
Member

Craft 4.5.12 is out with the fix for this.

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

2 participants