cancel
Showing results for 
Search instead for 
Did you mean: 

trying to order results based on relationship property in graphql?? (Complex query)

anorman
Node

Hello,

I have this query which works exactly as I want in cypher

MATCH (a:article) - [r:IN_TOPIC] -> (t:topic) where t.date = date('2022-06-05') return t.topicnum, r.pos, a.title order by t.topicnum, r.pos

Sadly, all I've managed to do trying using apollo studio to create an equivalent query is give myself a headache!

I can get close, but I cannot figure out how to have properly do the order by topicnumber (in topic), r.pos (in the relationship). 

Thanks in advance for any help/advice,

 

 Andre

1 REPLY 1

You can transform it step by step:

 

 

MATCH (a:article) - [r:IN_TOPIC] -> (t:topic) 
where t.date = date('2022-06-05') 
return t.topicnum, r.pos, a.title 
order by t.topicnum, r.pos

 

Not sure if I got it right, b/c I haven't use the rel-entities of the new library much.

But you can test it live in https://graphql-toolbox.neo4j.io/ with some data in your graph.

 

Something like this:

Schema
# (a:article) - [r:IN_TOPIC] -> (t:topic) where t.date = date('2022-06-05') return t.topicnum, r.pos, a.title order by t.topicnum, r.pos
type Topic {
  topicnum: Int!
  date: Date!
  inTopic: [ArticleInTopic!]! @relationship(direction:IN,type:"IN_TOPIC")
}
type ArticleInTopic {
  topic: Topic
  article: Article
  pos: Int
}
type Article {
  title: String!
}


query:

{
  topics(options: { sort: { topicnum: ASC } }, 
    		 where: { date: "2022-06-05" }) {
    topicnum
    inTopic(options: { sort: { pos: ASC } }) {
      article {
        title
      }
    }
  }
}