Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-21-2021 01:01 PM
Hi I'm using the GraphQL library and have a custom query that looks like this:
posts: [Post] @cypher(statement: """
MATCH (this)-[:HAS_MOVIE]->(m:Movie)<-[:TAGGED]-(review:Review)
RETURN DISTINCT review
LIMIT 10
ORDER BY review.date DESC
""")```
Just looks for any time a Playlist (i.e. `this`) has a movie, and then fetches all reviews for that playlist.
Because it's a custom query I can't just do posts with options `limit: 10` or feed it an offset, but I'm wondering if I can work around it and feed the custom query a variable from GraphQL? So even if it's not the built-in pagination it's still receiving a variable from the GraphQL query and leveraging that in the cypher query?
Thank you!
11-22-2021 07:29 AM
Hi Dan -
Any field arguments that you define in the typedefs for a Cypher directive field will be passed to the Cypher query defined in the directive as Cypher parameters. So for example this would allow you to specify the number of reviews to return at query time (by specifying a value for limit
as a field argument), in this case with a default value of 3.
(Using a default value for field arguments that will be passed as Cypher parameters is useful to ensure that parameter is always defined and you don't need to thnk about conditional logic for it in Cypher.)
posts(limit: Int! = 3): [Post] @cypher(statement: """
MATCH (this)-[:HAS_MOVIE]->(m:Movie)<-[:TAGGED]-(review:Review)
RETURN DISTINCT review
LIMIT $limit
ORDER BY review.date DESC
""")
11-22-2021 03:07 PM
How cool is that!! Thank you!
All the sessions of the conference are now available online