Skip to content

Graphql query fails if the collection is empty using the totalCount property #2060

Description

@epourail

Using a nested filter in a graphql query that returns an empty collection will fail if the totalCount property is requested.

In the following example, I want to filter the categories according to the topcategory's title and get the collection count

{
  categories(topcategory_title: "UnknownTopCategory") {
    totalCount
    edges {
      node {
        title
      }
    }
  }
}

By querying the totalCount property, the following error is displayed :

{
	"errors": [
		{
			"debugMessage": "Cannot return null for non-nullable field CategoryConnection.totalCount.",
			"message": "Internal server error",
			"category": "internal",
			"locations": [
				{
					"line": 3,
					"column": 3
				}
			],
			"path": [
				"categories",
				"totalCount"
			]
		}
	],
	"data": {
		"categories": null
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions