Neo4j with graphql help

I have simple neo4j & graphql example. Here is my typeDefs:

const typeDefs = `
        type Employee {
            eid: ID!
            name: String!
            title: String!
            email: String
            reportees: [Employee] @relation(name: "REPORTS_TO", direction: "BOTH")
        }

        type Query {
            getAllEmployees: [Employee] @cypher(statement: "MATCH (a:EMP)<-[:REPORTS_TO]-(b:EMP) RETURN a, b")
            getEmployee(name: String): [Employee] @cypher(statement: "MATCH (e:EMP) WHERE e.name contains $name RETURN e")
        }
`;

I'm able to fetch all data except reportees, which is always blank. What am I missing here? Here is sample cypher create scripts I used for this example.

CREATE (gma:EMP {eid:"1", name: “George Hill”, title:”President", email:”g.hill@test.com"})
CREATE (aba:EMP {eid:"2", name: “Anna Syntel”, title:”Manager”, email:”Anna.s@test.com"})
CREATE (noa:EMP {eid:"3", name: “Nagz Hello”, title:”Developer”, email:”n.hello@test.com"})
CREATE
        (aba)-[aa:REPORTS_TO]->(gma),
        (noa)-[bb:REPORTS_TO]->(aba)

Mostly it looks OK, but your nodes are labeled EMP while your Typedef is Employee, which doesn't match. I wouldn't expect that sample data to work with that typedef, because under the covers it will be looking for Employee nodes, and not EMP nodes as what is actually in the database.

Also, if you fix this labeling issue -- what cypher gets generated?

Also -- in your @relation you should probably specify direction: "OUT" and not both. "Reports to" is a single-direction relationship, and the way you've got it will confuse things because a boss will report to their direct report as well.

1 Like

Thank you @david.allen - you are correct
It works after changing to EMP and changing @relation to IN