Skip to content

[4.x]: GraphQl: Tried to load an unregistered type "*_MatrixField" #13622

@soerenmeier

Description

@soerenmeier

What happened?

Description

Trying to use a MatrixField type on a fragment fails in DEV_MODE=false.

Steps to reproduce

  1. Install craft
  2. Upgrade to pro
  3. Create a new Matrix Field with two blocks and each having a field
  4. Create a new section and add that MatrixField
  5. Make sure the section are graphql queyable and enable graphql
  6. Open GraphiQl
  7. Enter the graphql below and adjust the names
  8. If you run the snippet in DEV_MODE=true everything works fine
  9. But if you run it in DEV_MODE=false you get "Something went wrong when processing the GraphQL query." (make sure to clear the cache if it seems to work)
fragment MyMatrix on mymatrix_MatrixField {
  ... on mymatrix_block1_BlockType {
      block1field
    }
    ... on mymatrix_block2_BlockType {
      block2field
    }
}


query {
  entry(section: "mySection") {
    id
    title
    ... on mysection_mysection_Entry {
      mymatrix {
        ...MyMatrix
      }
    }
  }
}

Expected behavior

I expected the graphql output to work:

{
  "data": {
    "entry": {
      "id": "2",
      "title": "mySection",
      "mymatrix": []
    }
  }
}

Actual behavior

The output is just something went wrong, attached is a the error message in the logs:

{
  "errors": [
    {
      "message": "Something went wrong when processing the GraphQL query."
    }
  ]
}
Error Log

From storage/logs/*

2023-08-30 08:31:22 [web.ERROR] [craft\errors\GqlException] Tried to load an unregistered type "mymatrix_MatrixField". This can indicate both a typo in the query or an issue with the schema used. {"trace":["#0 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Type/Schema.php(350): craft\\gql\\TypeLoader::loadType('mymatrix_Matrix...')","#1 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Type/Schema.php(326): GraphQL\\Type\\Schema->loadType('mymatrix_Matrix...')","#2 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Utils/AST.php(579): GraphQL\\Type\\Schema->getType('mymatrix_Matrix...')","#3 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Utils/TypeInfo.php(436): GraphQL\\Utils\\AST::typeFromAST(Object(GraphQL\\Type\\Schema), Object(GraphQL\\Language\\AST\\NamedTypeNode))","#4 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Utils/TypeInfo.php(313): GraphQL\\Utils\\TypeInfo::typeFromAST(Object(GraphQL\\Type\\Schema), Object(GraphQL\\Language\\AST\\NamedTypeNode))","#5 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Language/Visitor.php(466): GraphQL\\Utils\\TypeInfo->enter(Object(GraphQL\\Language\\AST\\FragmentDefinitionNode))","#6 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Language/Visitor.php(277): GraphQL\\Language\\Visitor::GraphQL\\Language\\{closure}(Object(GraphQL\\Language\\AST\\FragmentDefinitionNode), 0, Object(GraphQL\\Language\\AST\\NodeList), Array, Array)","#7 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Validator/DocumentValidator.php(224): GraphQL\\Language\\Visitor::visit(Object(GraphQL\\Language\\AST\\DocumentNode), Array)","#8 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/Validator/DocumentValidator.php(116): GraphQL\\Validator\\DocumentValidator::visitUsingRules(Object(GraphQL\\Type\\Schema), Object(GraphQL\\Utils\\TypeInfo), Object(GraphQL\\Language\\AST\\DocumentNode), Array)","#9 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/GraphQL.php(153): GraphQL\\Validator\\DocumentValidator::validate(Object(GraphQL\\Type\\Schema), Object(GraphQL\\Language\\AST\\DocumentNode), Array)","#10 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/webonyx/graphql-php/src/GraphQL.php(93): GraphQL\\GraphQL::promiseToExecute(Object(GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter), Object(GraphQL\\Type\\Schema), 'fragment MyMatr...', NULL, Array, NULL, NULL, NULL, Array)","#11 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/services/Gql.php(504): GraphQL\\GraphQL::executeQuery(Object(GraphQL\\Type\\Schema), 'fragment MyMatr...', NULL, Array, NULL, NULL, NULL, Array)","#12 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/controllers/GraphqlController.php(185): craft\\services\\Gql->executeQuery(Object(craft\\models\\GqlSchema), 'fragment MyMatr...', NULL, NULL, false)","#13 [internal function]: craft\\controllers\\GraphqlController->actionApi()","#14 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)","#15 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)","#16 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction('api', Array)","#17 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/web/Application.php(304): yii\\base\\Module->runAction('graphql/api', Array)","#18 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/web/Application.php(607): craft\\web\\Application->runAction('graphql/api', Array)","#19 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/web/Application.php(283): craft\\web\\Application->_processActionRequest(Object(craft\\web\\Request))","#20 /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest(Object(craft\\web\\Request))","#21 /Users/soerenmeier/dunkel/test-craftcms/craft/web/index.php(12): yii\\base\\Application->run()","#22 {main}"],"memory":24070256,"exception":"[object] (craft\\errors\\GqlException(code: 0): Tried to load an unregistered type \"mymatrix_MatrixField\". This can indicate both a typo in the query or an issue with the schema used. at /Users/soerenmeier/dunkel/test-craftcms/craft/vendor/craftcms/cms/src/gql/TypeLoader.php:39)"} 

Craft CMS version

Craft Pro 4.5.3

PHP version

8.2.0

Operating system and version

Darwin 22.5.0

Database type and version

MySQL 5.7.39

Image driver and version

GD 8.2.0

Installed plugins and versions

none

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions