cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Issue (bug?) with rich relationship directions (GraphQL Java)

chris3
Graph Buddy

Using neo4j-graphql-java (1.5.0):

I have a hierarchical tree of users and "SPONSOR" relationships to form that tree. Each User has a single sponsor (outgoing to 1 User) and a "firstline" (multiple Users - incoming)

This is an excerpt of the schema:

type User {
	uid: ID!
	username: String
	.....
	sponsor: Sponsor
	firstline: [Sponsor]
}

type Sponsor @relation(name: "SPONSOR", from: "user", to: "sponsor") {
	user: User
	sponsor: User

	created: LocalDateTime
	cause: String
	.....
}

Is there a way to specify the direction on a rich relationship where from and to both use the same node type (e.g. in lines 5 and 6 telling the Sponsor type that in one case "this" =="user" and in the other case "this"=="sponsor")?

Because querying the above schema like this:

query {
	user(uid: "${uid}") {
		uid
		username
		.....
		sponsor {
			created
			cause 
			sponsor {
				uid
				.....
			}
		}
		firstline {
			user {
				uid
				.....
			}
		}
	}
}

...Generates this cypher :

MATCH (user:User)
WHERE user.uid = $userUid
CALL {
	WITH user
	OPTIONAL MATCH (user)<-[userSponsor:SPONSOR]-(userSponsorUser:User)
	RETURN userSponsor {
		.created,
		.cause,
		sponsor: userSponsorUser {
			.uid,
			.....
		}
	} AS userSponsor LIMIT 1
}
CALL {
	WITH user
	MATCH (user)<-[userFirstline:SPONSOR]-(userFirstlineUser:User)
	RETURN collect(userFirstline {
		user: userFirstlineUser {
			.uid,
			.....
		}
	}) AS userFirstline
}
RETURN user {
	.uid,
	.....
	sponsor: userSponsor,
	firstline: userFirstline
} AS user

The second subquery would be correct (firstline is INcoming on user) but the first subquery should be outgoing TO the sponsor user.
I thought maybe the match is based on the names ("user" and "sponsor") but it obviously isn't and the queries are always generated as if the relationship is incoming.

How can I work around this?


EDIT:
Allow me to tag on a 2nd question right away because it is related:
How can I order the "firstline" result by a property of the related nodes?

Without the rich relationship type I can query

.....
firstline(orderBy: number_asc) {
	uid
	number
	....
}
.....

But with the rich relationship I can not do something like:

.....
firstline(orderBy: user.number_asc) {
	user {
		uid
		number
		....
	}
}
.....

Is there a way?

3 REPLIES 3

You can provide the source/target in the field where you use the rich relationship type.

sponsor @relation(direction: OUT)

 see: https://github.com/neo4j-graphql/neo4j-graphql-java/blame/master/core/src/test/resources/relationshi...

Hi Michael,

thank you for your reply!

The docs at https://github.com/neo4j-graphql/neo4j-graphql-java didn not make it clear to me that it is possible to use a rich relationship plus "@relation".

Just to clarify for anyone looking for the answer to my original question: This is how to use the rich relationship definition "Sponsor" and declare a direction:

sponsor: Sponsor @relation(name: "SPONSOR", direction: OUT)
firstline: [Sponsor] @relation(name: "SPONSOR", direction: IN)

 

May I ask for a quick answer to my 2nd question of the original post: Can we filter / orderBy on properties of the related nodes while using rich relationship types?

Many thanks for your help!!!

@michael_hunger Is there no way to filter/order?