Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Cannot satisfy union type result with Map rather than Node #588

Open
amoe opened this issue Feb 10, 2021 · 1 comment
Open

Cannot satisfy union type result with Map rather than Node #588

amoe opened this issue Feb 10, 2021 · 1 comment

Comments

@amoe
Copy link

amoe commented Feb 10, 2021

Hi, I want to satisfy a union type with a Map. Regular types can be satisfied with maps without any problem, but when a union is involved, an error Expected a Node, got: Map is thrown. I tested satisfying the union with an actual Node, which works as expected. In this example that won't work because the identifier properties in the DB have different names: one uses id for its identifier and one uses name, but when they come out of GraphQL, the identifier should be id in both cases, hence using a Map to rename them.

Sample data:

CREATE (p:Person {id: "foo", gender: "M"}),
       (c:Circuit {name: "bar", size: 32}),
       (p)-[:INVOLVED_IN]->(c);

Sample query:

{
  entities {
    ... on Person {
       id
       gender
    }
    ... on Circuit {
      id
      size
    }
  }
}

Schema definition:

type Person {
    id: ID!
    type: String
    gender: String
}

type Circuit {
    id: ID!
    type: String
    size: Int
}

union Entity = Person | Circuit

type Query {
    entities: [Entity] @cypher(
        statement: """
            MATCH (c:Circuit)
            WITH COLLECT(DISTINCT {id: c.name, type: 'CIRCUIT', size: c.size}) AS circuitNodes
            OPTIONAL MATCH (p:Person)
            WITH COLLECT(DISTINCT {id: p.id, type: 'PERSON', gender: p.gender}) AS personNodes, circuitNodes
            OPTIONAL MATCH (p:Person)-[:INVOLVED_IN]->(c:Circuit)
            UNWIND personNodes + circuitNodes AS x
            RETURN x
        """
    )
}

Error that occurs:

{
  "errors": [
    {
      "message": "Expected a Node, got: Map{gender -> String(\"M\"), type -> String(\"PERSON\"), id -> String(\"foo\")}",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "entities"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "code": "Neo.ClientError.Statement.TypeError",
          "name": "Neo4jError",
          "stacktrace": [
            "Neo4jError: Expected a Node, got: Map{gender -> String(\"M\"), type -> String(\"PERSON\"), id -> String(\"foo\")}",
            "",
            "    at captureStacktrace (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-driver/lib/result.js:277:15)",
            "    at new Result (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-driver/lib/result.js:68:19)",
            "    at newCompletedResult (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-driver/lib/transaction.js:449:10)",
            "    at Object.run (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-driver/lib/transaction.js:287:14)",
            "    at Transaction.run (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-driver/lib/transaction.js:123:32)",
            "    at _callee2$ (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/neo4j-graphql-js/dist/index.js:222:35)",
            "    at tryCatch (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/regenerator-runtime/runtime.js:63:40)",
            "    at Generator.invoke [as _invoke] (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/regenerator-runtime/runtime.js:293:22)",
            "    at Generator.next (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/regenerator-runtime/runtime.js:118:21)",
            "    at asyncGeneratorStep (/home/amoe/dev/neo4j-graphql-js-return-aggregate-type/node_modules/@babel/runtime-corejs2/helpers/asyncToGenerator.js:5:24)"
          ]
        }
      }
    }
  ],
  "data": {
    "entities": null
  }
}

Using version 2.19.2.

@michaeldgraham
Copy link
Collaborator

#608

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

No branches or pull requests

2 participants