Skip to content

count(): Float cannot represent non numeric value #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DomVinyard opened this issue Jun 5, 2021 · 4 comments
Closed

count(): Float cannot represent non numeric value #237

DomVinyard opened this issue Jun 5, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@DomVinyard
Copy link

DomVinyard commented Jun 5, 2021

A custom cypher query which returns a count is not resolving correctly:

#typedefs
type Nested {
  count: Float @cypher(statement: "MATCH (n) RETURN count(n)")
}
type Query {
  test: Nested
}
`;
query {
  tests {
    count
  }
}

// error: "message": "Float cannot represent non numeric value: { low: 25, high: 0 }",
  • This only happens with nested queries, root queries are fine.
  • I am not seeing this same behaviour with sum() (even nested)

As seen: neo4j/neo4j-javascript-driver#225

If I try to return this as a scalar

scalar Foo
type Query {
  test: Foo @cypher(statement: "MATCH (n) RETURN count(n)")
}

# Error: `Long(25)` is not a collection or a map. Element access is only possible by performing a collection lookup using an integer index, or by performing a map lookup using a string key (found: Long(24)[Long(0)])

Our current workaround is a customer resolver

   count: async (test, _args, ctx) => {
      const cypher = String.raw`MATCH (n) RETURN count(n)`
      const res = await ctx.driver.session().run(cypher)
      const { low } = res.records[0].get(0)
      return low
  }
@DomVinyard DomVinyard added bug Something isn't working inbox labels Jun 5, 2021
@danstarns
Copy link
Contributor

Hi @DomVinyard. Our translation is initialized at the root, whereas your @cypher directive is on a field. Use the @cypher directive on the top-level Query and return the shape of Nested.

type Nested {
    count: Float
}

type Query {
    test: Nested
        @cypher(
            statement: """
            MATCH (n)
            WITH count(n) as count
            RETURN { count: count }
            """
        )
}

Then you can query:

{
  test {
    count
  }
}

and get a response like:

{
  "data": {
    "test": {
      "count": 8679
    }
  }
}

@DomVinyard
Copy link
Author

DomVinyard commented Jun 7, 2021

And if it's deeply nested?

type Nested3 {
    count: Float @cypher(statement: "MATCH (n) RETURN count(n)")
   # 10 other fields
}
type Nested2 {
    test2: Nested3
   # 10 other fields
}
type Nested1 {
    test1: Nested2
   # 10 other fields
}
type Query {
    test0: Nested1
   # 10 other fields
}
{
  test0 {
    # 10 other fields
    test1 {
      # 10 other fields
      test2 {
       # 10 other fields
        count
      }
    }
  }
}

?

@garlab
Copy link

garlab commented Jun 7, 2021

Our translation is initialized at the root, whereas your @cypher directive is on a field.

Could you expend on that? Do you mean the first example is not supposed to work?
I couldn't find any restriction of the sort in the doc. The documentation even provides this example of a cypher at an object field level:

type Movie {
    movieId: ID!
    title: String
    description: String
    year: Int
    actors(limit: Int = 10): [Actor]
        @relationship(type: "ACTED_IN", direction: IN)
    similarMovies(limit: Int = 10): [Movie]
        @cypher(
            statement: """
            MATCH (this)<-[:ACTED_IN]-(:Actor)-[:ACTED_IN]->(rec:Movie)
            WITH rec, COUNT(*) AS score ORDER BY score DESC
            RETURN rec LIMIT $limit
            """
        )
}

What's the difference here between similarMovies and count?

@darrellwarde
Copy link
Contributor

After much back and forth of thinking we had fixed this bug, it should finally be fully fixed by #297. 🤞 Apologies it took a while to get to this stage, it was a tricky bug to find but then very clear once we had found it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants