[Bug] Cannot query a relationship's nodes as subfields #605
Description
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