Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.
This repository was 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

Description

@AdrienLemaire

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

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