Skip to content

Should DEPENDS_ON cardinality between Modules equal the sum of their element dependencies? #56

@JohT

Description

@JohT

Hi all 👋,

when i compare the cardinality of the DEPENDS_ON relationship between two TS:Module nodes to the
sum of the DEPENDS_ON relationship cardinalities of their elements they are most of the time equal to each other.

Recently, i found some exceptions where i haven't found an explanation for. In those cases, the DEPENDS_ON cardinality between the TS:Module nodes is lower than the sum of the element DEPENDS_ON cardinalities (details below).

The source code of the example below shows re-exports or some types:

export type {
  ColorMapToken,
  ColorNeutralMapToken,
  CommonMapToken,
  FontMapToken,
  HeightMapToken,
  MapToken,
  SizeMapToken,
  StyleMapToken,
} from './maps';

Is this related to the re-export? Did i miss something else?

Thanks!

ModuleCardinalityLowerThanSumOfElements

Expected Behavior

The cardinality of the DEPENDS_ON relationship between two TS:Module nodes should equal their contained elements and their sum of the DEPENDS_ON relationship cardinalities. I'd expect the following query to have an empty result:

 MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:TS:Module)
 MATCH (source)-[elementDependency:DEPENDS_ON]->(moduleElement:TS)<-[:EXPORTS]-(target)
  WITH source
      ,target
      ,moduleDependency.cardinality       AS cardinality
      ,sum(elementDependency.cardinality) AS elementsCardinality
 WHERE cardinality < elementsCardinality
RETURN source.globalFqn, target.globalFqn, cardinality, elementsCardinality

Actual behavior

In some rare cases, the above query shows some results where the sum of the element dependency cardinalities exceeds the cardinality between their modules.

Steps to reproduce

Remark: The chosen repository contains a huge Typescript project that takes a while to clone, prepare and scan. I couldn't upload the json because it's bigger than GitHubs file size limit of 25MB. The resulting Graph database is about 3 GB big.

  • Clone https://github.com/ant-design/ant-design

  • Run npm install

  • Run npx --yes @jqassistant/ts-lce

  • Get the resulting report from .reports/jqa/ts-output.json

  • Scan the file with jQAssistant as described in the Usage section of the jqassistant-typescript-plugin

  • Start the local Neo4j server to see the results in the Browser.

  • Take the Cypher query from above to find the described cases.

  • Use the following, extended Cypher query to get more details and the nodes to explore this part of the Graph.

      MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:TS:Module)
      MATCH (source)-[elementDependency:DEPENDS_ON]->(moduleElement:TS)<-[:EXPORTS]-(target)
      WITH source
          ,target
          ,moduleDependency.cardinality            AS cardinality
          ,sum(elementDependency.cardinality)      AS elementsCardinality
          ,collect(DISTINCT moduleElement)         AS moduleElements
          ,count(DISTINCT moduleElement)           AS numberOfElements
          ,collect(DISTINCT labels(moduleElement)) AS elementLabels
      WHERE cardinality < elementsCardinality
      RETURN (elementsCardinality - cardinality) AS cardinalityDifference
          ,elementLabels
          ,count(*)                            AS numberOfCases
          ,max(numberOfElements)               AS maxNumberOfElements
          ,min(numberOfElements)               AS minNumberOfElements
          ,avg(numberOfElements)               AS avgNumberOfElements
          ,collect(DISTINCT source.globalFqn)[0..4] AS moduleNameExamples
          ,collect(DISTINCT target.globalFqn)[0..4] AS targetNameExamples
          ,collect(DISTINCT source)[0..4]           AS moduleExamples
          ,collect(DISTINCT target)[0..4]           AS targetExamples   
          ,collect(DISTINCT moduleElements)[0..4]   AS elementExamples   
      ORDER BY cardinalityDifference DESC, numberOfCases DESC 
      LIMIT 30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions