Skip to content

Some *Connection types are generated with an erroneous aggregate type leading to aggregation count queries within connections to fail #6206

@andreloeffelmann

Description

@andreloeffelmann

Describe the bug
Queries for aggregate counts (within connections) produce GraphQL errors for some GraphQL types.
It's some because I cannot detect a pattern determining when it works and when not.

Type definitions

type MediaAssetClass @node {
  id: String
}

To Reproduce
Steps to reproduce the behavior:

  1. Run a server with the type definintions
  2. Run the following Query:
query {
	mediaAssetClassesConnection {
		aggregate {
			count {
				nodes
			}
		}
	}
}
  1. See error:
{
	"errors": [
		{
			"message": "Cannot return null for non-nullable field MediaAssetMediaAssetClassClassesAggregateSelection.count.",
			"locations": [
				{
					"line": 3,
					"column": 42
				}
			],
			"path": [
				"mediaAssetClassesConnection",
				"aggregate",
				"count"
			],
			"extensions": {
				"code": "INTERNAL_SERVER_ERROR",
				"stacktrace": [
					"Error: Cannot return null for non-nullable field MediaAssetMediaAssetClassClassesAggregateSelection.count."
				]
			}
		}
	],
	"data": null
}

Expected behavior
A response containing the aggregate counts should be returned, no error

Further information
I traced the bug down to @neo4j\graphql\dist\translate\queryAST\factory\Operations\ConnectionFactory.js line 232 in function hydrateConnectionOperationWithAggregation at:

const resolveTreeAggregateFields = resolveTreeAggregate?.fieldsByTypeName[target.operations.aggregateTypeNames.connection];

resolveTreeAggregateFields resolves to undefined. This is because target.operations.aggregateTypeNames.connection equals to MediaAssetClassAggregate whereas the object resolveTreeAggregate?.fieldsByTypeName contains a key named MediaAssetMediaAssetClassClassesAggregateSelection only. I guess the problem is that this object should contain the key MediaAssetClassAggregate?

The generated GraphQL schema for the MediaAssetClassesConnection type looks like this:

type MediaAssetClassesConnection {
  edges: [MediaAssetClassesRelationship!]!
  totalCount: Int!
  pageInfo: PageInfo!
  aggregate: MediaAssetMediaAssetClassClassesAggregateSelection!
}

I think this is already wrong - the aggregate type should be called MediaAssetClassAggregate.

Now the strange thing: this does work for other GraphQL types like MediaAsset, MediaAssetType.
It does not work for MediaAssetVersion, too.
Seems like there is a crazy bug when generating the schema based on the name of GraphQL types?

System:

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