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

[Bug] Cannot query a relationship's nodes as subfields #605

Open
AdrienLemaire opened this issue Apr 19, 2021 · 1 comment
Open

[Bug] Cannot query a relationship's nodes as subfields #605

AdrienLemaire opened this issue Apr 19, 2021 · 1 comment

Comments

@AdrienLemaire
Copy link
Contributor

AdrienLemaire commented Apr 19, 2021

Given the schema

type A {
  id
}
type B {
  id
}
type Rels @relation(name: "HAS_REL") {
  from: A!
  to: B!
  at: DateTime!
}
type Query {
  getRelations: [Rels!]
    @cypher(
      statement: """
      MATCH (:A)-[rel:HAS_REL]->(:B)
      RETURN rel;
      """
    )
}

When trying to query a node as subfield of the relationship

const GET_RELATIONS = gql`
  query GetRelations {
    getRelations {
      from {
        id
      }
      to {
        id
      }
      at
    }
  }
`;

We're getting an error

[GraphQL error]: Message: Cannot read property 'value' of undefined, Path: getRelations

If using named fields

type Rels @relation(name: "HAS_REL", from: "a", to: "b") {
  a: A!
  b: B!
  at: DateTime!
}

Then error changes to:

[GraphQL error]: Message: Cannot read property 'name' of undefined, Path: getRelations

We'll temporarily change our query to return one of the nodes, and fetch nodes & relationship data from that node. This causes issues to generate a unique id on relationships client-side

const typePolicies = {
  Rels: {
    keyFields: ["a", ["id"], "b", ["id"]],
  },
};

If returning a node and the relationship as subfield, the initial node cannot be queried from the relationship's subfields anymore.

We are being forced to create undesired intermediate nodes as a result.

Being able to return relationships and get related node data sounds like a usecase neo4j-graphql-js should support

@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