DEV Community

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

Collapse
 
abiyasa profile image
Abiyasa Suhardi • Edited

Thanks for the article 👍 What I really like about GRANDStack is I can express the data model and the Cypher query in my GraphQL Schema.

I have 2 questions from your article:

  • You declared the WorkedAt type on your schema but I haven't seen it being used. Let say you want to expand the Person type to also return the list of company they've worked in the past, including the start & end date. How would the schema would look like?
  • On the footnote, you mentioned that this is a simple use case and would not be optimized for very large data set queries. Could you elaborate more about this? for example, your schema is not optimized for that, or there is a scaling problem on GRAND stack itself, or how to make it more optimized for a large data set

Sorry if I ask too much. Thanks a lot 🙂

Collapse
 
muddybootscode profile image
Michael Porter

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 • Edited

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...