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]: GraphQl: Tried to load an unregistered type "*_MatrixField" #13622

Closed
soerenmeier opened this issue Aug 30, 2023 · 7 comments
Closed

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

soerenmeier opened this issue Aug 30, 2023 · 7 comments
Assignees

Comments

@soerenmeier
Copy link

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

@wmdhosting
Copy link

got same error after upgrade to 4.5.2 last day.. on production..
GraphQl: Tried to load an unregistered type "*_MatrixField"..

@nickdenys
Copy link

I've got the same issue on both 4.5.2 and 4.5.3. I've rolled back to 4.4.17 for now.
When trying to mutate a Matrix field, I get the following error:

Tried to load an unregistered type "activityTimeDates_MatrixBlockContainerInput". This can indicate both a typo in the query or an issue with the schema used.

If I used the type "QueryArgument" instead I get this error:

Variable \"$timeDates\" of type \"[QueryArgument]\" used in position expecting type \"[activityTimeDates_MatrixBlockContainerInput]

The mutation looks like this:

mutation editActivity(
  $id: ID!,
  $timeDates: [activityTimeDates_MatrixBlockContainerInput]
  $timeDatesSortOrder: [QueryArgument],
) {
  save_activities_Entry(
    id: $id
    activityTimeDates: {blocks: $timeDates, sortOrder: $timeDatesSortOrder}
  ) {
    timeDates: activityTimeDates {
      ... on activityTimeDates_day_BlockType {
        id
      }
    }
  }
}

@howells
Copy link

howells commented Sep 1, 2023

I'm experiencing the same issue, but when querying *_NeoFields. There's no rhyme nor reason why some queries work and others that also include the same fields, don't.

@i-just i-just self-assigned this Sep 5, 2023
@i-just
Copy link
Contributor

i-just commented Sep 5, 2023

Hi all, thanks for reporting!

I’ve narrowed it down to GQL lazy-loading improvements introduced in v4.5. I’m working on a solution now.

@brandonkelly
Copy link
Member

This is now fixed for the next release! You can get it early by changing your craftcms/cms requirement to dev-develop#b9d8ec55bc7cf20321a2fbfd20ce41785fd5f6bb as 4.5.3, and running composer update.

@jacobgraf
Copy link

FYI, I also hit this bug and as long as I added a __typehandle field into the Matrix field query, it worked again. Hoping it's fixed in the release @brandonkelly mentioned above, but in the meantime, this is what patched it for us.

@brandonkelly
Copy link
Member

Craft 4.5.4 is out with this 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

7 participants