Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When returning the result from the apoc.path.subgraphAll from the server to the function updateWithFunction, the visualization is not updating #351

Open
kunalj1994 opened this issue Jul 1, 2023 · 3 comments

Comments

@kunalj1994
Copy link

kunalj1994 commented Jul 1, 2023

Expected Behavior (Mandatory)

The visualization should update with the nodes and relationships from the response.

Actual Behavior (Mandatory)

Nothing happens, but the same query when executed with updateWithCypher function updates the visualization and shows the right nodes and relationships.

How to Reproduce the Problem

By using this query -

MATCH (p) where ID(p) = ${nodeId}
      CALL apoc.path.subgraphAll(p, {
          minLevel: 0,
          maxLevel: 1
      })
      YIELD nodes, relationships
      RETURN nodes, relationships

and capturing the result in a variable and passing it to updateWithFunction.

Simple Example

const config: NeovisConfig = {
  visConfig: {
    height: '100%',
    width: '100%',
    interaction: {
      hover: true,
      hoverConnectedEdges: true,
      selectConnectedEdges: false,
      multiselect: true,
      zoomView: true,
    },
    physics: {
      barnesHut: {
        gravitationalConstant: -50000,
        avoidOverlap: 0.4,
      },
    },
    nodes: {
      shape: 'circle',
      widthConstraint: 80,
    },
    edges: {
      hoverWidth: 2,
      selectionWidth: 0,
      smooth: {
        enabled: true,
        type: 'continuous',
        roundness: 0.15,
      },
      arrows: {
        to: {
          enabled: true,
          type: 'arrow',
          scaleFactor: 0.5,
        },
      },
    },
  },
  groupAsLabel: true,

  initialCypher: 'MATCH (n) RETURN n',
}
Node id can come from the clicked event mentioned below.
const result =  <result of this query - MATCH (p) where ID(p) = ${nodeId}
      CALL apoc.path.subgraphAll(p, {
          minLevel: 0,
          maxLevel: 1
      })
      YIELD nodes, relationships
      RETURN nodes, relationships
}>

vis.registerOnEvent(NeoVisEvents.ClickNodeEvent, e => {
  vis.updateWithFunction(() => result)
})

Specifications (Mandatory)

Currently used versions

Versions

  • OS:macOS
  • Library: 2.1.0
  • Neo4j: 5.9
@kunalj1994
Copy link
Author

kunalj1994 commented Jul 1, 2023

I have went through the code thoroughly and pinpointed two instances in the code where I think the bug could lie,
When running the createSingleRecord function, since the input is a JSON it doesnt recognize it as a instance of Record, so it executes the corresponding if statement which then executes this line

record = new Neo4j.types.Record(
        record.keys,
        fields.map(dumbToNeo4j),
        (record as any)._fieldLookup,
      )

This dumbToNeo4j function looks to me as the culprit, because when running a regular query, the structure looks like this -

[
    {
      keys: ['n', 'r'],
      length: 2,
      _fields: [
       {},{}
      ],
      _fieldLookup: {
        n: 0,
        r: 1,
      },
    },
    ]

But when running the apoc.path.subgraph query, the resulting structure looks like this -

[{
  "keys": ["nodes", "relationships"],
  "length": 2,
  "_fields": [
    [{}, {}],
    [{}, {}]
  ],
  "_fieldLookup": {
    "nodes": 0,
    "relationships": 1
  }
}]

So this dumbToNeo4j is unable to account for _fields being a nested array and returns this result - {"keys":["nodes","relationships"],"length":2,"_fields":[null,null],"_fieldLookup":{"nodes":0,"relationships":1}}

@thebestnom
Copy link
Collaborator

It should account for fields in array, but maybe I forgot, Ill try to fix that, fun to have to do deseriallization myself as neo4j didn't wrote a seriallizinzation function

@kunalj1994
Copy link
Author

Perfect, thank you for your swift reply and looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants