I am getting this error from my graphql query - Double(6.695317e+04) (of class org.neo4j.values.stor

Hi there,

I have added a @cypher directive to my GraphQL Type - getDistances.

I am getting an error returned from my graphQL query when I make a query using getDistances. Can you please tell me what might be causing the problem ?

const typeDefs = gql`
    type Company {
        id: Int
        postCode: String
        name: String
        ratingValue: String
        structuralScore: String
        location: Point
        localAuthority: String
        isHospitality: Boolean
        hygieneScore: String
        confidenceInManagementScore: String
        businessType: String
        addressLineOne: String
        addressLineTwo: String
        addressLineThree: String
        addressLineFour: String
        getDistances(startLat: Float, startLng: Float, endLat: Float, endLng: Float): [Company]
            @cypher(
                statement: """
                WITH
                point({longitude: $startLng, latitude: $startLat, height: 100}) AS p1,
                point({latitude: $endLat, longitude: $endLng, height: 100}) AS p2
                RETURN point.distance(p1, p2) AS dist
                """)
    }
`;

GraphQL query

{
  companies {
   getDistances(startLat: 51.400616, startLng: -0.2645342, endLat: 51.6443052331424, endLng: 0.61920005649669) {
    name 
}   
  }
}

Error response

{
  "errors": [
    {
      "message": "Double(6.695317e+04) (of class org.neo4j.values.storable.DoubleValue)",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "companies"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "code": "Neo.DatabaseError.Statement.ExecutionFailed",
          "name": "Neo4jError",
          "retriable": false,
          "stacktrace": [
            "Neo4jError: Double(6.695317e+04) (of class org.neo4j.values.storable.DoubleValue)",
            "",
            "    at captureStacktrace (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/result.js:611:17)",
            "    at new Result (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/result.js:105:23)",
            "    at newCompletedResult (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:502:12)",
            "    at Object.run (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:334:20)",
            "    at Transaction.run (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/transaction.js:175:34)",
            "    at Executor.transactionRun (/Users/james/development/graphql_server/node_modules/@neo4j/graphql/dist/classes/Executor.js:138:28)",
            "    at /Users/james/development/graphql_server/node_modules/@neo4j/graphql/dist/classes/Executor.js:126:25",
            "    at TransactionExecutor._safeExecuteTransactionWork (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:141:26)",
            "    at TransactionExecutor.<anonymous> (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:128:46)",
            "    at step (/Users/james/development/graphql_server/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:52:23)"
          ]
        }
      }
    }
  ],
  "data": null
}

Hi @jcct100 -

I think the issue is that the Cypher query in your @cypher directive is returning the distance value, but according to the GraphQL type definitions the getDistances field is expected to be an array of Company objects/nodes.

What exactly do you want this getDistances field to be? Changing the type of the field to Float should fix the error:

 getDistances(startLat: Float, startLng: Float, endLat: Float, endLng: Float): Float

but if you wanted to do something like return other companies within some radius distance of the currently resolved Company then it would look something like this:

getDistances(radius: Int = 100): [Company] @cypher( statement: """
  MATCH (c:Company) WHERE point.distance(this.location, c.location) < $radius
  RETURN c                
""")

You're getting that error because the statement you have provided to the cypher directive returns a Float type. However, your type definitions expect a list of Company objects. The following type definition should work for you:

    type Company {
        id: Int
        postCode: String
        name: String
        ratingValue: String
        structuralScore: String
        location: Point
        localAuthority: String
        isHospitality: Boolean
        hygieneScore: String
        confidenceInManagementScore: String
        businessType: String
        addressLineOne: String
        addressLineTwo: String
        addressLineThree: String
        addressLineFour: String
        getDistances(startLat: Float, startLng: Float, endLat: Float, endLng: Float): Float
            @cypher(
                statement: """
                WITH
                point({longitude: $startLng, latitude: $startLat, height: 100}) AS p1,
                point({latitude: $endLat, longitude: $endLng, height: 100}) AS p2
                RETURN point.distance(p1, p2) AS dist
                """
            )
    }