DEV Community

loading...

Discussion on: Neo4j and GraphQL Heavenly Match #1 - Directional Relationships

Collapse
muddybootscode profile image
Michael Porter Author

No worries Abiyasa let me see if I can answer those questions:
1) In the schema, you can already get a list of the places that a person has WorkedAt the field returns an array of workplaces like so:

workedAt: [WorkPlace] @relation(name: "WORKED_AT", direction: "OUT")

As for the start and end dates as well as the company worked at you're going to have to make some compromises because you can only return scalar types from the cypher queries so:

workHistory: [string] @cypher (
   statement: "MATCH (this)-[r:WORKED_AT]->(w:WorkPlace) return r.startDate, r.endDate, w.name"
)

and then create a json object or something of that nature to take care of it.

As for a more performant version you would need to include in between the Person and workplace nodes, an intermediary node that captures the workplace information i.e. startDate, endDate, etc. because you can't index properties on a relationship and that slows the query down on massive data sets.

Collapse
abiyasa profile image
Abiyasa Suhardi

Thanks, Michael! That's really helpful, especially about returning scalar types, which I didn't know before about this limitation

Thread Thread
muddybootscode profile image
Michael Porter Author

No problem, in this case you're probably going to want to return some kind of custom scalar type, like a JSON object. You can find information about there here in the Apollo docs apollographql.com/docs/graphql-too...