neo4j-graphql / neo4j-graphql-js

NOTE: This project is no longer actively maintained. Please consider using the official Neo4j GraphQL Library (linked in README).
Other
609 stars 148 forks source link

Sorting only works on returned fields #512

Open taseroth opened 4 years ago

taseroth commented 4 years ago

It looks like the orderBy only works on returned values. The following query:

{
  GetUser(filter: {screenName: "taseroth"}) {
    posts(first: 20, orderBy: createdAt_desc) {
      retweets {
        users {
          name
          screenName
        }
      }
      isRetweet
      retweetCount
      favoriteCount
      text
    }
  }
}

produces the following cypher error:

"Invalid input '}': expected whitespace, comment, literal entry, property selector, variable selector or all properties selector (line 1, column 524 (offset: 523))\n\"MATCH (`user`:`User`) WHERE (`user`.screenName = $filter.screenName) RETURN `user` {posts: [sortedElement IN apoc.coll.sortMulti([(`user`)-[:`POSTS`]->(`user_posts`:`Tweet`) | `user_posts` {retweets: [(`user_posts`)-[:`RETWEETS`]->(`user_posts_retweets`:`Tweet`) | `user_posts_retweets` {users: [(`user_posts_retweets`)<-[:`POSTS`]-(`user_posts_retweets_users`:`User`) | `user_posts_retweets_users` { .name , .screenName }] }] , .isRetweet , .retweetCount , .favoriteCount , .text }], ['createdAt']) | sortedElement { .*,  }][..20] } AS `user`\"\n 

For reverence, this is the schema (wip):

type User {
   _id: Long!
   createdAt: LocalDateTime
   description: String
   followersCount: Int
   friendsCount: Int
   id: String!
   isProtected: Boolean
   location: String
   name: String
   profileImageURL: String
   screenName: String!
   tweetCount: Int
   verified: Boolean
   posts: [Tweet] @relation(name: "POSTS", direction: OUT)
   follows: [User] @relation(name: "FOLLOWS", direction: OUT)
   tweets: [Tweet] @relation(name: "MENTIONED", direction: IN)
   top10Hashtags: [String] @cypher(statement: """
   match p=((this)-[:POSTS]->(:Tweet)<-[*1..2]-(h:Hashtag)) with h.name as hastag, count(p) as cnt order by cnt desc limit 10
   return collect(hastag)
   """)
}

type Hashtag {
   _id: Long!
   name: String!
   tags: [Tweet] @relation(name: "TAGS", direction: OUT)
}

type Link {
   _id: Long!
   errorCode: Int
   errorMessage: String
   url: String!
   links_to: [Url] @relation(name: "LINKS_TO", direction: OUT)
   tweets: [Tweet] @relation(name: "CONTAINS", direction: IN)
}

type Url {
   _id: Long!
   url: String!
   part_of: [Site] @relation(name: "PART_OF", direction: OUT)
   links: [Link] @relation(name: "LINKS_TO", direction: IN)
}

type Site {
   _id: Long!
   name: String!
   urls: [Url] @relation(name: "PART_OF", direction: IN)
}

type Tweet  {
   _id: Long!
   createdAt: LocalDateTime
   favoriteCount: Int
   id: Int!
   isRetweet: Boolean
   lang: String
   retweetCount: Int
   text: String
   mentioned: [User] @relation(name: "MENTIONED", direction: OUT)
   reply_to: [Tweet] @relation(name: "REPLY_TO", direction: OUT)
   contains: [Link] @relation(name: "CONTAINS", direction: OUT)
   retweets: [Tweet] @relation(name: "RETWEETS", direction: OUT)
   quotes: [Tweet] @relation(name: "QUOTES", direction: OUT)
   users: [User] @relation(name: "POSTS", direction: IN)
   hashtags: [Hashtag] @relation(name: "TAGS", direction: IN)
}

type Query {
   GetUser: [User]
   GetHashtag: [Hashtag]
}
michaeldgraham commented 4 years ago

Hey there @taseroth, I think this should be fixed in the most recent version, as of a few pull requests ago, so I have to ask - what version are you currently using?

taseroth commented 4 years ago

Sorry, I should check github more often. I used it in https://github.com/taseroth/twitter-gvandstack/blob/main/api/package.json

so 2.16.3 I guess.

I can try again if you like

michaeldgraham commented 3 years ago

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608