Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I represent Neo4j relationship properties in my Graphql Schema?

I have a Neo4j DB with relationships that have properties such as [:FRIENDS {since: "11/2015"}]. I need to represent the "since" property in the GraphQl Schema. RELAY has something call "edges" an apparently this is how they implement this feature but I am not using RELAY.....I didn't see anything in Apollo (maybe I missed it). Can someone show me how to do this?

like image 713
MichaelE Avatar asked Sep 11 '17 11:09

MichaelE


1 Answers

Ok...so in order to get what I wanted which was to present both the node and the relationship (edge) to graphql I did what I would call a work-around by returning object.assign(node,relationship) to graphql....the downside is that I have to define a type nodeRel {} to receive the combined objects but it works. Also, the node and relationship objects can't have similar named properties. I can now answer the question how long John and Mary are friends or what groups John belongs to and how long he has been a member....Schema snippet:

    ... memberOf    : [Group]
  groupStatus  : [MemberProfile]
  attended    : [Meeting]
  submittedReport   : [Report]
  post        : [Post]

}

type MemberProfile {
  name          : String
  location      : String
  created       : String
  since         : String
  role          : String
  financial     : Boolean
  active        : Boolean
  }

Resolver:

groupStatus(voter) {
            let session = driver.session(),
                params = { voterid: voter.voterid },
                query = `
                        MATCH (v:Voter)-[r:MEMBER_OF]->(g:Group)
                        WHERE v.voterid = $voterid
                        RETURN g AS group,r AS rel;
                        `
            return session
                .run(query, params)
                .then(result => {
                    return result.records.map(record => {
                        return Object.assign(record.get("group").properties, record.get("rel").properties)
                    })
                })
        },

I hope this help someone else....

like image 85
MichaelE Avatar answered Sep 21 '22 23:09

MichaelE