craftcms / gatsby-helper

Craft CMS helper plugin for Gatsby.
https://plugins.craftcms.com/gatsby-helper
MIT License
15 stars 6 forks source link

[4.4.17]: GraphQL Node Changes | Tried to load an unregistered type \"Section_Type_Entry\". This can indicate both a typo in the query or an issue with the schema used. #31

Closed delasign closed 1 year ago

delasign commented 1 year ago

What happened?

A node changes call produces an internal server error:

GraphQL Call:

query nodeChanges {  
    nodesUpdatedSince (since: "2023-08-13 19:46:53" site: ["default"]) { nodeId nodeType siteId}
    nodesDeletedSince (since: "2023-08-13 19:46:53") { nodeId nodeType siteId}
}

Description

I noticed an error with your GraphQL that is causing my system to break.

I initially thought it was exclusive to the gatsby-source-craft plugin but it turns out it also causes an internal server error in the CraftCMS GraphQL.

The issue is detailed here: https://github.com/craftcms/gatsby-source-craft/issues/114

Please note that the Private Schema does not have access to subscribers default entries. image

If I use the "Full Schema" this issue dissapears image

Steps to reproduce

  1. Create a CraftCMS project that uses the GraphQL
  2. When creating a token, do not give it access to everything.
  3. Make a change outside of the schema that the token has access to.
  4. Run the query for nodeChanges similar to the one below in the GraphiQL

Expected behavior

I believe that the expected behavior is it should not find updated nodes outside of the schema.

Actual behavior

Please note that the Private Schema does not have access to subscribers default entries.

"errors": [
    {
      "debugMessage": "Tried to load an unregistered type \"subscribers_default_Entry\". This can indicate both a typo in the query or an issue with the schema used.",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "trace": [
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Type/Schema.php",
          "line": 350,
          "call": "craft\\gql\\TypeLoader::loadType('subscribers_default_Entry')"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Type/Schema.php",
          "line": 326,
          "call": "GraphQL\\Type\\Schema::loadType('subscribers_default_Entry')"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/gatsby-helper/src/gql/resolvers/UpdatedNode.php",
          "line": 60,
          "call": "GraphQL\\Type\\Schema::getType('subscribers_default_Entry')"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 623,
          "call": "craft\\gatsbyhelper\\gql\\resolvers\\UpdatedNode::resolve(null, array(2), array(2), instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 550,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, 'craft\\gatsbyhelper\\gql\\resolvers\\UpdatedNode::resolve', null, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1195,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Query, null, instance of ArrayObject(1), array(1))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 264,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: Query, null, array(0), instance of ArrayObject(2))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 215,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/Executor/Executor.php",
          "line": 156,
          "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 162,
          "call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, array(2), array(1), 'nodeChanges', null)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 94,
          "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, 'query nodeChanges {  \n    nodesUpdatedSince (since: \"2023-08-13 19:46:53\" site: [\"default\"]) { nodeId nodeType siteId}\n    nodesDeletedSince (since: \"2023-08-13 19:46:53\") { nodeId nodeType siteId}\n}', null, array(2), array(1), 'nodeChanges', null, array(26))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/cms/src/services/Gql.php",
          "line": 512,
          "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, 'query nodeChanges {  \n    nodesUpdatedSince (since: \"2023-08-13 19:46:53\" site: [\"default\"]) { nodeId nodeType siteId}\n    nodesDeletedSince (since: \"2023-08-13 19:46:53\") { nodeId nodeType siteId}\n}', null, array(2), array(1), 'nodeChanges', null, array(26))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/cms/src/controllers/GraphqlController.php",
          "line": 181,
          "call": "craft\\services\\Gql::executeQuery(instance of craft\\models\\GqlSchema, 'query nodeChanges {  \n    nodesUpdatedSince (since: \"2023-08-13 19:46:53\" site: [\"default\"]) { nodeId nodeType siteId}\n    nodesDeletedSince (since: \"2023-08-13 19:46:53\") { nodeId nodeType siteId}\n}', array(1), 'nodeChanges', true)"
        },
        {
          "call": "craft\\controllers\\GraphqlController::actionApi()"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/yiisoft/yii2/base/InlineAction.php",
          "line": 57,
          "function": "call_user_func_array(array(2), array(0))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/yiisoft/yii2/base/Controller.php",
          "line": 178,
          "call": "yii\\base\\InlineAction::runWithParams(array(1))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/yiisoft/yii2/base/Module.php",
          "line": 552,
          "call": "yii\\base\\Controller::runAction('api', array(1))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/cms/src/web/Application.php",
          "line": 304,
          "call": "yii\\base\\Module::runAction('graphql/api', array(1))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/cms/src/web/Application.php",
          "line": 607,
          "call": "craft\\web\\Application::runAction('graphql/api', array(1))"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/craftcms/cms/src/web/Application.php",
          "line": 283,
          "call": "craft\\web\\Application::_processActionRequest(instance of craft\\web\\Request)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/vendor/yiisoft/yii2/base/Application.php",
          "line": 384,
          "call": "craft\\web\\Application::handleRequest(instance of craft\\web\\Request)"
        },
        {
          "file": "/srv/app/craft3-xs7n/htdocs/web/index.php",
          "line": 26,
          "call": "yii\\base\\Application::run()"
        }
      ]
    }
  ]

Craft CMS version

4.4.17

PHP version

8.0.28

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Amazon S3 | 2.0.3 Field Manager | 3.0.6 Mail Service (Custom, Non Released Plugin) | 1.0.0 Redactor | 3.0.4 Remote Sync | 4.1.1 Super Table | 3.0.9 Gatsby Helper | 2.0.1

i-just commented 1 year ago

Hi, thanks for reporting! I raised a PR to improve this behaviour.

delasign commented 1 year ago

Thanks @i-just, I saw the PR was merged - how do I get it into my project ?

brandonkelly commented 1 year ago

Gatsby Helper 1.1.4 (Craft 3) and 2.0.2 (Craft 4) were just released wit the fix. Thanks again!

delasign commented 1 year ago

Just confirmed the fix works on both the GraphiQL and on Gatsby. Thanks @i-just @brandonkelly !