GithubHelp home page GithubHelp logo

Comments (3)

danstarns avatar danstarns commented on July 28, 2024 1

Digging deeper - If we take the query that's failing:

{
  movies(where: { title_CONTAINS: "Matrix Reloaded, The" }) {
    title
    actors(options: { limit: 1 }) {
      name
      acted_in(options: { limit: 3, sort: { year: DESC } }) {
        title
      }
    }
  }
}

The cypher produced is:

MATCH (this:Movie)
WHERE this.title CONTAINS $this_title_CONTAINS

RETURN this {
  .title, 
  actors: [ (this)<-[:ACTED_IN]-(this_actors:Actor) | this_actors { 
      .name, 
      acted_in: apoc.coll.sortMulti([ (this_actors)-[:ACTED_IN]->(this_actors_acted_in:Movie) | this_actors_acted_in { .title } ], ['year'])[..3] 
  } ][..1] 
} AS this

Looking at what neo4j-graphql-js does... We should still project the property so it can be sorted on:

MATCH (this:Movie)
WHERE this.title CONTAINS $this_title_CONTAINS

RETURN this {
  .title, 
  actors: [ (this)<-[:ACTED_IN]-(this_actors:Actor) | this_actors { 
      .name, 
-     acted_in: apoc.coll.sortMulti([ (this_actors)-[:ACTED_IN]->(this_actors_acted_in:Movie) | this_actors_acted_in { .title } ], ['year'][..3],
+     acted_in: apoc.coll.sortMulti([ (this_actors)-[:ACTED_IN]->(this_actors_acted_in:Movie) | this_actors_acted_in { .title, .year } ], ['year'])[..3] 
  } ][..1] 
} AS this

This does mean that on particular usages, such as this issue raised, we are selecting a field that is not asked for and relying on the GraphQL runtime to filter out that field.

from graphql.

danstarns avatar danstarns commented on July 28, 2024

@johnymontana Thanks for the clarity and steps to reproduce I can produce this locally also.

from graphql.

johnymontana avatar johnymontana commented on July 28, 2024

Right, it's an unfortunate consequence of using apoc.coll.sortMulti as a post-processing step of the pattern comprehension. If the Cypher pattern comprehension supported ordering then the additional field wouldn't need to be selected and the database would just take care of it.

There's an outstanding card to add this functionality to Cypher here, I'll ping that card with this example as another use case where it would make sense to add to Cypher.

from graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.