Skip to content

[5.x]: GraphQL: NullValueNode error when using relatedToEntries: null on children field #16431

@Thierry-Muehlemann

Description

@Thierry-Muehlemann

What happened?

Description

GraphQL Filter relatedToEntries doesn't handle null values on children.

Steps to reproduce

  1. create a section of type structure
  2. Have some nested entries
  3. Try this GraphQL query:
query {
  entries {
   title
    children(relatedToEntries: null) {
      title
    }
  }
}

Expected behavior

Expected to list all results. Works if specified at entries level or if none of the entries were nested.

working Query

query {
# specified at entries level
  entries(relatedToEntries: null) {
   title
# not specified at children level
    children {
      title
    }
  }
}

Result

{
"data": {
    "entries": [
      {
        "title": "Test1",
        "children": []
      },
      {
        "title": "Test2",
        "children": []
      },
      {
        "title": "Test3",
        "children": []
      },
    ...
    ]
}
}

This one fails:

query {
# not specified at entries level
  entries {
   title
# specified at children level
    children(relatedToEntries: null) {
      title
    }
  }
}

If relatedToEntries is set to null i would expect them to work the same.

Actual behavior

GraphQL fails with a NullValueNode error:

{
  "errors": [
    {
      "debugMessage": "Undefined property: GraphQL\\Language\\AST\\NullValueNode::$value",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "file": "/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php",
      "line": 225,
      "trace": [
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php",
          "line": 79,
          "call": "yii\\base\\ErrorHandler::handleError(2, 'Undefined property: GraphQL\\Language\\AST\\NullValueNode::$value', '/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php', 225)"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php",
          "line": 225,
          "call": "craft\\web\\ErrorHandler::handleError(2, 'Undefined property: GraphQL\\Language\\AST\\NullValueNode::$value', '/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php', 225)"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php",
          "line": 181,
          "call": "craft\\gql\\ElementQueryConditionBuilder::_extractArgumentValue(instance of GraphQL\\Language\\AST\\ArgumentNode)"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php",
          "line": 428,
          "call": "craft\\gql\\ElementQueryConditionBuilder::_extractArguments(instance of GraphQL\\Language\\AST\\NodeList(1))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/ElementQueryConditionBuilder.php",
          "line": 160,
          "call": "craft\\gql\\ElementQueryConditionBuilder::_traversAndBuildPlans(instance of GraphQL\\Language\\AST\\FieldNode, instance of craft\\elements\\db\\EagerLoadPlan, null, null, 'global')"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/base/ElementResolver.php",
          "line": 113,
          "call": "craft\\gql\\ElementQueryConditionBuilder::extractQueryConditions(null)"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/gql/base/ElementResolver.php",
          "line": 50,
          "call": "craft\\gql\\base\\ElementResolver::prepareElementQuery(null, array(0), array(2), instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 623,
          "call": "craft\\gql\\base\\ElementResolver::resolve(null, array(0), array(2), instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 549,
          "call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, 'craft\\gql\\resolvers\\elements\\Entry::resolve', null, instance of GraphQL\\Type\\Definition\\ResolveInfo)"
        },
        {
          "file": "/var/www/html/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": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 264,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: Query, null, array(0), instance of ArrayObject(1))"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 215,
          "call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/Executor/Executor.php",
          "line": 156,
          "call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 161,
          "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), null, null)"
        },
        {
          "file": "/var/www/html/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 93,
          "call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, '# Welcome to GraphiQL\n#\n# GraphiQL is an in-browser tool for writing, validating, and\n# testing GraphQL queries.\n#\n# Type queries into this side of the screen, and you will see intelligent\n# typeaheads aware of the current GraphQL type schema and live syntax and\n# validation errors highlighted within the text.\n#\n# GraphQL queries typically start with a \"{\" character. Lines that start\n# with a # are ignored.\n#\n# An example GraphQL query might look like:\n#\n#     {\n#       field(arg: \"value\") {\n#         subField\n#       }\n#     }\n#\n# Keyboard shortcuts:\n#\n#  Prettify Query:  Shift-Ctrl-P (or press the prettify button above)\n#\n#     Merge Query:  Shift-Ctrl-M (or press the merge button above)\n#\n#       Run Query:  Ctrl-Enter (or press the play button above)\n#\n#   Auto Complete:  Ctrl-Space (or just start typing)\n#\n\nquery {\n  entries {\n   title\n    children(relatedToEntries: null) {\n      title\n    }\n  }\n}\n', null, array(2), array(1), null, null, array(26))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/services/Gql.php",
          "line": 526,
          "call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, '# Welcome to GraphiQL\n#\n# GraphiQL is an in-browser tool for writing, validating, and\n# testing GraphQL queries.\n#\n# Type queries into this side of the screen, and you will see intelligent\n# typeaheads aware of the current GraphQL type schema and live syntax and\n# validation errors highlighted within the text.\n#\n# GraphQL queries typically start with a \"{\" character. Lines that start\n# with a # are ignored.\n#\n# An example GraphQL query might look like:\n#\n#     {\n#       field(arg: \"value\") {\n#         subField\n#       }\n#     }\n#\n# Keyboard shortcuts:\n#\n#  Prettify Query:  Shift-Ctrl-P (or press the prettify button above)\n#\n#     Merge Query:  Shift-Ctrl-M (or press the merge button above)\n#\n#       Run Query:  Ctrl-Enter (or press the play button above)\n#\n#   Auto Complete:  Ctrl-Space (or just start typing)\n#\n\nquery {\n  entries {\n   title\n    children(relatedToEntries: null) {\n      title\n    }\n  }\n}\n', null, array(2), array(1), null, null, array(26))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/controllers/GraphqlController.php",
          "line": 195,
          "call": "craft\\services\\Gql::executeQuery(instance of craft\\models\\GqlSchema, '# Welcome to GraphiQL\n#\n# GraphiQL is an in-browser tool for writing, validating, and\n# testing GraphQL queries.\n#\n# Type queries into this side of the screen, and you will see intelligent\n# typeaheads aware of the current GraphQL type schema and live syntax and\n# validation errors highlighted within the text.\n#\n# GraphQL queries typically start with a \"{\" character. Lines that start\n# with a # are ignored.\n#\n# An example GraphQL query might look like:\n#\n#     {\n#       field(arg: \"value\") {\n#         subField\n#       }\n#     }\n#\n# Keyboard shortcuts:\n#\n#  Prettify Query:  Shift-Ctrl-P (or press the prettify button above)\n#\n#     Merge Query:  Shift-Ctrl-M (or press the merge button above)\n#\n#       Run Query:  Ctrl-Enter (or press the play button above)\n#\n#   Auto Complete:  Ctrl-Space (or just start typing)\n#\n\nquery {\n  entries {\n   title\n    children(relatedToEntries: null) {\n      title\n    }\n  }\n}\n', array(1), null, true)"
        },
        {
          "call": "craft\\controllers\\GraphqlController::actionApi()"
        },
        {
          "file": "/var/www/html/vendor/yiisoft/yii2/base/InlineAction.php",
          "line": 57,
          "function": "call_user_func_array(array(2), array(0))"
        },
        {
          "file": "/var/www/html/vendor/yiisoft/yii2/base/Controller.php",
          "line": 178,
          "call": "yii\\base\\InlineAction::runWithParams(array(1))"
        },
        {
          "file": "/var/www/html/vendor/yiisoft/yii2/base/Module.php",
          "line": 552,
          "call": "yii\\base\\Controller::runAction('api', array(1))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
          "line": 350,
          "call": "yii\\base\\Module::runAction('graphql/api', array(1))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
          "line": 649,
          "call": "craft\\web\\Application::runAction('graphql/api', array(1))"
        },
        {
          "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
          "line": 312,
          "call": "craft\\web\\Application::_processActionRequest(instance of craft\\web\\Request)"
        },
        {
          "file": "/var/www/html/vendor/yiisoft/yii2/base/Application.php",
          "line": 384,
          "call": "craft\\web\\Application::handleRequest(instance of craft\\web\\Request)"
        },
        {
          "file": "/var/www/html/web/index.php",
          "line": 12,
          "call": "yii\\base\\Application::run()"
        }
      ]
    }
  ],
  "data": {
    "entries": null
  }
}

Craft CMS version

5.5.9

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions