How to represent Neo4j relationship properties in my Graphql schema?

I have a Neo4j database with relationships that have properties such as [: FRIENDS {since: "11/2015"}]. I need to present the β€œsince” property in the GraphQl schema. RELAY something causes "edges", apparently, this is how they implement this function, but I do not use RELAY ..... I did not see anything in Apollo (maybe I missed it). Can someone show me how to do this?

+6
neo4j graphql apollo-server
source share
1 answer

Ok ... therefore, to get what I wanted to represent both node and the edge relation to graphql, I did what I would call work-around, returning object.assign (node, relation) to graphql .... the disadvantage is that I have to define the type nodeRel {} to get combined objects, but it works. In addition, node objects and relationships cannot have similar named properties. Now I can answer the question of how long John and Mary have been friends or groups to which John belongs 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) }) }) }, 

Hope this helps someone else ...

+5
source share

All Articles